home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / intell.cpp < prev    next >
C/C++ Source or Header  |  1996-03-07  |  186KB  |  8,269 lines

  1. /******************************************************************************
  2. *******************************************************************************/
  3.  
  4. // Player intelligence and decision making routines...
  5.  
  6. /******************************************************************************
  7. *****************************************************************************/
  8.  
  9. #include "global.h"
  10. #include "defines.h"
  11. #include "externs.h"
  12. #include "data.h"
  13. #include "audio.h"                            // Kev's audio calls.
  14. #include "front.h"
  15. #include "eurofrnt\euro_int.h"
  16.  
  17. extern match_data match_info;
  18. extern team_info game_data[];
  19. extern float save_offs[];
  20. extern setup_info setup;
  21. extern stad_info stadlist[];
  22. extern void reselect_a();
  23. extern void reselect_b();
  24.  
  25. /******************************************************************************
  26. *****************************************************************************/
  27.  
  28. //  Intelligence Flags and Variables...
  29.  
  30. char cross_on=FALSE;
  31.  
  32. /******************************************************************************
  33. *****************************************************************************/
  34.  
  35. short get_there_time(int p_num,float x,float y)
  36. {
  37.     stop_and_face=FALSE;
  38.  
  39.     must_face_time=0;
  40.     int t1=0;
  41.     int t2=0;
  42.     int mft1=0;
  43.     int mft2=0;
  44.     int t;
  45.     int mft;
  46.     float d;
  47.     float rate=full_spd(&teams[p_num-1]);  // Running speed!
  48.     float px,py;
  49.     px=teams[p_num-1].tm_x;
  50.     py=teams[p_num-1].tm_y;
  51.     x=x-px;
  52.     y=y-py;        // Offset.
  53.  
  54.     float sx=x;
  55.     float sy=y;
  56.  
  57.     float xd=teams[p_num-1].tm_xdis;
  58.     float yd=teams[p_num-1].tm_ydis; //Current facing dir.
  59.  
  60.     float max=MAX_TURN2;
  61.     float old_max=max;
  62.     float cmax=cos(max);
  63.     float ox,oy,a,turn_spd,last_a;
  64.  
  65. // Player must have ball slightly
  66.  
  67.     if (teams[p_num-1].tm_act<=TURN_ACT)
  68.     {
  69. // Can i turn on the spot?
  70.         a=angle_to_xy(x,y,xd,yd);
  71.         t1=ABS(acos(a)/max);        // time to turn!
  72.  
  73. // Time to go straight to point...
  74.         d=calc_dist(x,y);
  75.         t1+=d/rate+1;
  76.  
  77.         if (must_face)
  78.         {
  79. // User forced to face in a particular direction (after getting to target)...
  80.             a=angle_to_xy(must_face_x,must_face_y,x/d,y/d);
  81.             mft1=ABS(acos(a)/max)+1;        // time to turn!
  82.         }
  83.     }
  84.     else
  85.         t1=2000;
  86.  
  87.     a=angle_to_xy(x,y,xd,yd);
  88.     last_a=a;
  89.  
  90.     d=calc_dist(x,y);
  91.  
  92. // Time to get to target point...
  93.     for (int i=0; i<50; i++)
  94.     {
  95.  
  96. // Init run...
  97.         if (d<IM_THERE_DIST)
  98.             break;
  99.         else
  100.             t2++;
  101.  
  102. // Go forward...
  103.         turn_spd=(1.0+a)/2;
  104.  
  105.         x-=xd*rate*turn_spd;        // Move on...
  106.         y-=yd*rate*turn_spd;
  107.  
  108. // Turn...
  109.  
  110.         d=calc_dist(x,y);
  111.  
  112.         ox=xd;
  113.         oy=yd;
  114.  
  115.         max=old_max;
  116.  
  117.         if (a<cmax)
  118.         {
  119. // Need to turn...
  120.  
  121.             if ((x*oy/d)>(y*ox/d))
  122.                 max=-max;
  123.  
  124.             xd=(ox*cos(max))-(oy*sin(max));
  125.             yd=(oy*cos(max))+(ox*sin(max));
  126.         }
  127.         else
  128.         {
  129. // Final turn...
  130. //            xd=x/d;
  131. //            yd=y/d;
  132.             t2+=d/rate;
  133.             if (d-((t2-1)*rate)>.1)
  134.                 t2++;
  135.             break;
  136.         }
  137.  
  138.         last_a=a;
  139.         a=angle_to_xy(x,y,xd,yd);
  140.  
  141.         if (last_a>a)
  142. // Getting further forget it!
  143.         {
  144.             t2=2000;
  145.             break;        // (exit)
  146.         }
  147.     }
  148.  
  149.     if (i>50)
  150.         t=2000;        // Could not find intersection!
  151.  
  152.     if (must_face)
  153.     {
  154. // User forced to face in a particular direction (after getting to target)...
  155.         a=angle_to_xy(must_face_x,must_face_y,xd,yd);
  156.         mft2=ABS(acos(a)/max)+1;        // time to turn!
  157.     }
  158.  
  159.     if ((t1+mft1)<(t2+mft2))
  160.     {
  161. // Rotate and run...
  162.         t=t1+mft1;
  163.         mft=mft1;
  164.         d=calc_dist(sx,sy);
  165.         x_face=sx/d;        // New dir...
  166.         y_face=sy/d;
  167.         stop_and_face=TRUE;
  168.     }
  169.     else
  170.     {
  171. // Turn and run...
  172.         t=t2+mft2;
  173.         mft=mft2;
  174.         x_face=x/d;        // New dir...
  175.         y_face=y/d;
  176.     }
  177.  
  178.     if (must_face)
  179.     {
  180.         x_face=must_face_x;
  181.         y_face=must_face_y;
  182.         must_face_time=mft;
  183.     }
  184.  
  185.     return(t);
  186. }
  187.  
  188. /******************************************************************************
  189. *****************************************************************************/
  190.  
  191. short get_facing_opp_dir(match_player *player)
  192. {
  193.  
  194. /*
  195.  
  196. Output: 1 = Side On.
  197.          -1 = Behind.
  198.           0 = Face On.
  199.  
  200. */
  201.  
  202.     int d=get_dir(ballx-player->tm_x,bally-player->tm_y);
  203. // Direction to ball!
  204.  
  205.     int opp=teams[ball_poss-1].face_dir;
  206.     if (opp==d)
  207.         return(-1);
  208.  
  209.     d=d-opp;
  210.  
  211.     if (d<0)
  212.         d+=8;
  213.  
  214.     if ((d==1) || (d==7))
  215.         return(-1);
  216.     
  217.     if ((d==2) || (d==6))
  218.         return(1);
  219.     else
  220.         return(0);
  221. }
  222.  
  223. /******************************************************************************
  224. *****************************************************************************/
  225.  
  226. char thinking(match_player *player)
  227. {
  228.     int f=(130-player->tm_flair)/2;
  229.     int t=logic_cnt/f;
  230.     int r=logic_cnt-(t*f);
  231.     return(!r);
  232. }
  233.  
  234. /******************************************************************************
  235. *****************************************************************************/
  236.  
  237. char plr_facing(float x,float y,match_player *player)
  238. {
  239.     float xd=player->tm_xdis;
  240.     float yd=player->tm_ydis;
  241.     float d=calc_dist(x,y);
  242.     float a=((x*xd)+(y*yd))/d;
  243.     if (a>FACING_ANGLE)            // 5 degrees!
  244.         return(TRUE);
  245.     else
  246.         return(FALSE);
  247. }
  248.  
  249. /******************************************************************************
  250. *****************************************************************************/
  251.  
  252. char plr_facing_goal(float x,float y,match_player *player)
  253. {
  254.  
  255. // Is the player facing between the goal posts of goal(x,y)?
  256.  
  257.     float xd=player->tm_xdis;
  258.     float yd=player->tm_ydis;
  259.  
  260.     if ((x>0 && xd<0) || (x<0 && xd>0))
  261.         return(FALSE);
  262.  
  263.     float yt;
  264.     if (user_controlled)
  265.         yt=(top_post_y-prat*6)-player->tm_y;
  266.     else
  267.         yt=top_post_y-player->tm_y;
  268.  
  269.     float d=calc_dist(x,yt);
  270.     float xt=x/d;
  271.     yt=yt/d;
  272.  
  273.     float yb;
  274.     if (user_controlled)
  275.         yb=(bot_post_y+prat*6)-player->tm_y;
  276.     else
  277.         yb=bot_post_y-player->tm_y;
  278.  
  279.     d=calc_dist(x,yb);
  280.     float xb=x/d;
  281.     yb=yb/d;
  282.  
  283.     char dir=0;
  284.  
  285.     if ((xt*yd)>(yt*xd))
  286.         dir=TRUE;
  287.  
  288.     if ((xb*yd)>(yb*xd))
  289.     {
  290.         if (dir)
  291.             return(FALSE);
  292.         else
  293.             return(TRUE);
  294.     }
  295.     else
  296.     {
  297.         if (dir)
  298.             return(TRUE);
  299.         else
  300.             return(FALSE);
  301.     }
  302.     return(FALSE);
  303. }
  304.  
  305. /******************************************************************************
  306. *****************************************************************************/
  307.  
  308. void run_back(match_player *player)
  309. {
  310.     player->tm_off=-2;
  311.     if (player->tm_player<12)
  312. // Team A...
  313.     {
  314.         init_run_act(player,defense_b-(prat*3),player->tm_y,TRUE);
  315.     }
  316.     else
  317. // Team B...
  318.     {
  319.         init_run_act(player,defense_a+(prat*3),player->tm_y,TRUE);
  320.     }
  321. }
  322.  
  323. /******************************************************************************
  324. *****************************************************************************/
  325.  
  326. void keeper_boxes()
  327. {
  328.     if ((teams[KP_A-1].tm_x>(prat*16)) || (teams[KP_A-1].tm_y>(cntspot_y+(19*prat)))
  329.         || (teams[KP_A-1].tm_y<(cntspot_y-(19*prat))) || (teams[KP_A-1].tm_x<0))
  330.  
  331.         keeper_a_in_box=FALSE;
  332.     else
  333.         keeper_a_in_box=TRUE;
  334.  
  335.     if ((teams[KP_B-1].tm_x<pitch_len-(prat*16)) || (teams[KP_B-1].tm_y>(cntspot_y+(19*prat)))
  336.         || (teams[KP_B-1].tm_y<(cntspot_y-(19*prat))) || (teams[KP_B-1].tm_x>pitch_len))
  337.  
  338.         keeper_b_in_box=FALSE;
  339.     else
  340.         keeper_b_in_box=TRUE;
  341. }
  342.  
  343. /******************************************************************************
  344. *****************************************************************************/
  345.  
  346. void reset_ideas(match_player *player)
  347. {
  348.     player->tm_strike=FALSE;
  349.     player->special=FALSE;
  350.     player->tm_z=0;
  351.  
  352.     if (player->int_move!=I_OFF)
  353.     {
  354.         if ((player->int_move==I_INTERCEPT) && (player->tm_act==RUN_ACT))
  355.             player->go_cnt=1;            // Stop running!
  356.  
  357.         if (player->int_move==I_RUN_ON)
  358.         {
  359.             want_pass=0;
  360.             player->int_move=0;
  361.             player->int_cnt=0;
  362.         }
  363.  
  364.         if (player->int_cnt)
  365.         {
  366.               if (player->tm_player==interceptor_a)
  367.                 interceptor_a=0;
  368.  
  369.             if (player->tm_player==interceptor_b)
  370.                 interceptor_b=0;
  371.  
  372.             player->int_move=0;
  373.             player->int_cnt=0;
  374.         }
  375.     }
  376. }
  377.  
  378. /******************************************************************************
  379. *****************************************************************************/
  380.  
  381. void reset_all_ideas()
  382. {
  383.     for (int i=0; i<players; i++)
  384.     {
  385.         reset_ideas(&teams[i]);
  386.         teams[i].tm_leave=FALSE;
  387.     }
  388.     keep_dive=FALSE;
  389. }
  390.  
  391. /******************************************************************************
  392. *****************************************************************************/
  393.  
  394. void reset_leaves()
  395. {
  396.     for (int i=0; i<players; i++)
  397.     {
  398.         teams[i].tm_leave=FALSE;
  399.     }
  400. }
  401.  
  402. /******************************************************************************
  403. *****************************************************************************/
  404.  
  405. void save_in_zone_a(match_player *player,float x,float y,float z,int bp,char forced)
  406. {
  407.     float factor;
  408.     keeper_on_grnd=FALSE;
  409.     keeper_will_save=TRUE;
  410.     int zone=1;
  411.     if (z<SAVE_FEET_HGT)
  412. // Feet level...
  413.     {
  414.         if (bp<=SAVE_AFOOTB_TIME/keeper_spd && !keep_dive)
  415.         {
  416.             keeper_contact=MCC_AFOOTB;
  417.  
  418.             factor=1./((float)bp/(SAVE_AFOOTB_TIME/keeper_spd));
  419.             if (factor>max_kp_margin && !forced)
  420.             {
  421. // Ball is too fast!
  422.                 factor=max_kp_margin;
  423.                 keeper_will_save=FALSE;
  424.                 player->tm_fstep=MC_AFOOTB_FS*factor*keeper_spd;
  425.             }
  426.             else
  427.                 player->tm_fstep=keeper_contact/bp;
  428.  
  429.             if (player->tm_fstep>=1)
  430.                 player->tm_fstep=1;
  431.  
  432.             save_block=TRUE;
  433.             init_save_act(player,x,y,z,MC_AFOOTB,zone,bp,(int)(SAVE_AFOOTB_TIME/keeper_spd));
  434.         }
  435.         else
  436.             if (bp<=SAVE_AFOOTC_TIME/keeper_spd  || keep_dive)
  437.             {
  438.                 keeper_contact=MCC_AFOOTC;
  439.  
  440.                 factor=1./((float)bp/(SAVE_AFOOTC_TIME/keeper_spd));
  441.                 if (factor>max_kp_margin && !forced)
  442.                 {
  443. // Ball is too fast!
  444.                     factor=max_kp_margin;
  445.                     keeper_will_save=FALSE;
  446.                     player->tm_fstep=MC_AFOOTC_FS*factor*keeper_spd;
  447.                 }
  448.                 else
  449.                     player->tm_fstep=keeper_contact/bp;
  450.  
  451.                 if (player->tm_fstep>=1)
  452.                     player->tm_fstep=1;
  453.  
  454.                 save_block=FALSE;
  455.                 keeper_on_grnd=TRUE;
  456.                 init_save_act(player,x,y,z,MC_AFOOTC,zone,bp,(int)(SAVE_AFOOTC_TIME/keeper_spd));
  457.             }
  458.             else
  459. // Move to best position...
  460.             {
  461.                 shot_acknowledged=1;
  462.             }
  463.     }
  464.     else
  465.         if (z<SAVE_CHEST_HGT)
  466. // Chest level...
  467.         {
  468.              if (bp<=SAVE_ABODYB_TIME/keeper_spd && !keep_dive)
  469.             {
  470.                 keeper_contact=MCC_ABODYB;
  471.  
  472.                 factor=1./((float)bp/(SAVE_ABODYB_TIME/keeper_spd));
  473.                 if (factor>max_kp_margin && !forced)
  474.                 {
  475. // Ball is too fast!
  476.                     factor=max_kp_margin;
  477.                     keeper_will_save=FALSE;
  478.                     player->tm_fstep=MC_ABODYB_FS*factor*keeper_spd;
  479.                 }
  480.                 else
  481.                     player->tm_fstep=keeper_contact/bp;
  482.  
  483.                 if (player->tm_fstep>=1)
  484.                     player->tm_fstep=1;
  485.  
  486.                 save_block=TRUE;
  487.                 init_save_act(player,x,y,z,MC_ABODYB,zone,bp,(int)(SAVE_ABODYB_TIME/keeper_spd));
  488.             }
  489.             else
  490.                  if (bp<=SAVE_ABODYC_TIME/keeper_spd  || keep_dive)
  491.                 {
  492.                     keeper_contact=MCC_ABODYC;
  493.  
  494.                     factor=1./((float)bp/(SAVE_ABODYC_TIME/keeper_spd));
  495.                     if (factor>max_kp_margin && !forced)
  496.                     {
  497. // Ball is too fast!
  498.                         factor=max_kp_margin;
  499.                         keeper_will_save=FALSE;
  500.                         player->tm_fstep=MC_ABODYC_FS*factor*keeper_spd;
  501.                     }
  502.                     else
  503.                         player->tm_fstep=keeper_contact/bp;
  504.  
  505.                     if (player->tm_fstep>=1)
  506.                         player->tm_fstep=1;
  507.  
  508.                     save_block=FALSE;
  509.                     init_save_act(player,x,y,z,MC_ABODYC,zone,bp,(int)(SAVE_ABODYC_TIME/keeper_spd));
  510.                 }
  511.                 else
  512. // Move to best position...
  513.                 {
  514.                     shot_acknowledged=1;
  515.                 }
  516.         }
  517.         else
  518.             if (z<SAVE_HEAD_HGT)
  519. // Head level...
  520.             {
  521.                  if (bp<=SAVE_AHEADB_TIME/keeper_spd && !keep_dive)
  522.                 {
  523.                     keeper_contact=MCC_AHEADB;
  524.  
  525.                     factor=1./((float)bp/(SAVE_AHEADB_TIME/keeper_spd));
  526.                     if (factor>max_kp_margin && !forced)
  527.                     {
  528. // Ball is too fast!
  529.                         factor=max_kp_margin;
  530.                         keeper_will_save=FALSE;
  531.                         player->tm_fstep=MC_AHEADB_FS*factor*keeper_spd;
  532.                     }
  533.                     else
  534.                         player->tm_fstep=keeper_contact/bp;
  535.  
  536.                     if (player->tm_fstep>=1)
  537.                         player->tm_fstep=1;
  538.  
  539.                     save_block=TRUE;
  540.                     init_save_act(player,x,y,z,MC_AHEADB,zone,bp,(int)(SAVE_AHEADB_TIME/keeper_spd));
  541.                 }
  542.                 else
  543.                      if (bp<=SAVE_AHEADC_TIME/keeper_spd  || keep_dive)
  544.                     {
  545.                         keeper_contact=MCC_AHEADC;
  546.  
  547.                         factor=1./((float)bp/(SAVE_AHEADC_TIME/keeper_spd));
  548.                         if (factor>max_kp_margin && !forced)
  549.                         {
  550. // Ball is too fast!
  551.                             factor=max_kp_margin;
  552.                             keeper_will_save=FALSE;
  553.                             player->tm_fstep=MC_AHEADC_FS*factor*keeper_spd;
  554.                         }
  555.                         else
  556.                             player->tm_fstep=keeper_contact/bp;
  557.  
  558.                         if (player->tm_fstep>=1)
  559.                             player->tm_fstep=1;
  560.  
  561.                         save_block=FALSE;
  562.                         init_save_act(player,x,y,z,MC_AHEADC,zone,bp,(int)(SAVE_AHEADC_TIME/keeper_spd));
  563.                     }
  564.                     else
  565. // Move to best position...
  566.                     {
  567.                         shot_acknowledged=1;
  568.                     }
  569.             }
  570.             else
  571.                 if (z<SAVE_JUMP_HGT)
  572. // Above head level...
  573.                 {
  574.                      if (bp<=SAVE_AJUMPB_TIME/keeper_spd && !keep_dive)
  575.                     {
  576.                         keeper_contact=MCC_AJUMPB;
  577.  
  578.                         factor=1./((float)bp/(SAVE_AJUMPB_TIME/keeper_spd));
  579.                         if (factor>max_kp_margin && !forced)
  580.                         {
  581. // Ball is too fast!
  582.                             factor=max_kp_margin;
  583.                             keeper_will_save=FALSE;
  584.                             player->tm_fstep=MC_AJUMPB_FS*factor*keeper_spd;
  585.                         }
  586.                         else
  587.                             player->tm_fstep=keeper_contact/bp;
  588.  
  589.                         if (player->tm_fstep>=1)
  590.                             player->tm_fstep=1;
  591.  
  592.                         save_block=TRUE;
  593.                         init_save_act(player,x,y,z,MC_AJUMPB,zone,bp,(int)(SAVE_AJUMPB_TIME/keeper_spd));
  594.                     }
  595.                     else
  596.                          if (bp<=SAVE_AJUMPC_TIME/keeper_spd  || keep_dive)
  597.                         {
  598.                             keeper_contact=MCC_AJUMPC;
  599.  
  600.                             factor=1./((float)bp/(SAVE_AJUMPC_TIME/keeper_spd));
  601.                             if (factor>max_kp_margin && !forced)
  602.                             {
  603. // Ball is too fast!
  604.                                 factor=max_kp_margin;
  605.                                 keeper_will_save=FALSE;
  606.                                 player->tm_fstep=MC_AJUMPC_FS*factor*keeper_spd;
  607.                             }
  608.                             else
  609.                                 player->tm_fstep=keeper_contact/bp;
  610.  
  611.                             if (player->tm_fstep>=1)
  612.                                 player->tm_fstep=1;
  613.  
  614.                             save_block=FALSE;
  615.                             init_save_act(player,x,y,z,MC_AJUMPC,zone,bp,(int)(SAVE_AJUMPC_TIME/keeper_spd));
  616.                         }
  617.                         else
  618. // Move to best position...
  619.                         {
  620.                             shot_acknowledged=1;
  621.                         }
  622.                 }
  623. }
  624.  
  625. /******************************************************************************
  626. *****************************************************************************/
  627.  
  628. void save_in_zone_b(match_player *player,float x,float y,float z,int bp,char forced)
  629. {
  630.     float factor;
  631.     keeper_on_grnd=FALSE;
  632.     keeper_will_save=TRUE;
  633.     int zone=2;
  634.     if (z<SAVE_FEET_HGT)
  635. // Feet level...
  636.     {
  637.         if (bp<=SAVE_BFOOTB_TIME/keeper_spd && !keep_dive)
  638.         {
  639.             keeper_contact=MCC_BFOOTB;
  640.  
  641.             factor=1./((float)bp/(SAVE_BFOOTB_TIME/keeper_spd));
  642.             if (factor>max_kp_margin && !forced)
  643.             {
  644. // Ball is too fast!
  645.                 factor=max_kp_margin;
  646.                 keeper_will_save=FALSE;
  647.                 player->tm_fstep=MC_BFOOTB_FS*factor*keeper_spd;
  648.             }
  649.             else
  650.                 player->tm_fstep=keeper_contact/bp;
  651.  
  652.             if (player->tm_fstep>=1)
  653.                 player->tm_fstep=1;
  654.  
  655.             save_block=TRUE;
  656.             init_save_act(player,x,y,z,MC_BFOOTBL,zone,bp,(int)(SAVE_BFOOTB_TIME/keeper_spd));
  657.         }
  658.         else
  659.             if (bp<=SAVE_BFOOTC_TIME/keeper_spd  || keep_dive)
  660.             {
  661.                 keeper_contact=MCC_BFOOTC;
  662.  
  663.                 factor=1./((float)bp/(SAVE_BFOOTC_TIME/keeper_spd));
  664.                 if (factor>max_kp_margin && !forced)
  665.                 {
  666. // Ball is too fast!
  667.                     factor=max_kp_margin;
  668.                      keeper_will_save=FALSE;
  669.                      player->tm_fstep=MC_BFOOTC_FS*factor*keeper_spd;
  670.                  }
  671.                  else
  672.                      player->tm_fstep=keeper_contact/bp;
  673.  
  674.                 if (player->tm_fstep>=1)
  675.                     player->tm_fstep=1;
  676.  
  677.                 save_block=FALSE;
  678.                 keeper_on_grnd=TRUE;
  679.                 init_save_act(player,x,y,z,MC_BFOOTCL,zone,bp,(int)(SAVE_BFOOTC_TIME/keeper_spd));
  680.             }
  681.             else
  682. // Move to best position...
  683.             {
  684.                 shot_acknowledged=1;
  685.             }
  686.     }
  687.     else
  688.         if (z<SAVE_CHEST_HGT)
  689. // Chest level...
  690.         {
  691.              if (bp<=SAVE_BBODYB_TIME/keeper_spd && !keep_dive)
  692.             {
  693.                 keeper_contact=MCC_BBODYB;
  694.                 factor=1./((float)bp/(SAVE_BBODYB_TIME/keeper_spd));
  695.                 if (factor>max_kp_margin && !forced)
  696.                 {
  697. // Ball is too fast!
  698.                     factor=max_kp_margin;
  699.                     keeper_will_save=FALSE;
  700.                     player->tm_fstep=MC_BBODYB_FS*factor*keeper_spd;
  701.                 }
  702.                 else
  703.                      player->tm_fstep=keeper_contact/bp;
  704.  
  705.                 if (player->tm_fstep>=1)
  706.                     player->tm_fstep=1;
  707.  
  708.                 save_block=TRUE;
  709.                 keeper_on_grnd=TRUE;
  710.                 init_save_act(player,x,y,z,MC_BBODYBL,zone,bp,(int)(SAVE_BBODYB_TIME/keeper_spd));
  711.             }
  712.             else
  713.                  if (bp<=SAVE_BBODYC_TIME/keeper_spd || keep_dive)
  714.                 {
  715.                     keeper_contact=MCC_BBODYC;
  716.                     factor=1./((float)bp/(SAVE_BBODYC_TIME/keeper_spd));
  717.                     if (factor>max_kp_margin && !forced)
  718.                     {
  719. // Ball is too fast!
  720.                         factor=max_kp_margin;
  721.                         keeper_will_save=FALSE;
  722.                         player->tm_fstep=MC_BBODYC_FS*factor*keeper_spd;
  723.                     }
  724.                     else
  725.                          player->tm_fstep=keeper_contact/bp;
  726.  
  727.                     if (player->tm_fstep>=1)
  728.                         player->tm_fstep=1;
  729.  
  730.                     save_block=FALSE;
  731.                     keeper_on_grnd=TRUE;
  732.                     init_save_act(player,x,y,z,MC_BBODYCL,zone,bp,(int)(SAVE_BBODYC_TIME/keeper_spd));
  733.                 }
  734.                 else
  735. // Move to best position...
  736.                 {
  737.                     shot_acknowledged=1;
  738.                 }
  739.         }
  740.         else
  741.             if (z<SAVE_HEAD_HGT)
  742. // Head level...
  743.             {
  744.                  if (bp<=SAVE_BHEADB_TIME/keeper_spd && !keep_dive)
  745.                 {
  746.                     keeper_contact=MCC_BHEADB;
  747.                     factor=1./((float)bp/(SAVE_BHEADB_TIME/keeper_spd));
  748.                     if (factor>max_kp_margin && !forced)
  749.                     {
  750. // Ball is too fast!
  751.                         factor=max_kp_margin;
  752.                         keeper_will_save=FALSE;
  753.                         player->tm_fstep=MC_BHEADB_FS*factor*keeper_spd;
  754.                     }
  755.                     else
  756.                          player->tm_fstep=keeper_contact/bp;
  757.  
  758.                     if (player->tm_fstep>=1)
  759.                         player->tm_fstep=1;
  760.  
  761.                     save_block=TRUE;
  762.                     init_save_act(player,x,y,z,MC_BHEADBL,zone,bp,(int)(SAVE_BHEADB_TIME/keeper_spd));
  763.                 }
  764.                 else
  765.                      if (bp<=SAVE_BHEADC_TIME/keeper_spd || keep_dive)
  766.                     {
  767.                         keeper_contact=MCC_BHEADC;
  768.                         factor=1./((float)bp/(SAVE_BHEADC_TIME/keeper_spd));
  769.                         if (factor>max_kp_margin && !forced)
  770.                         {
  771. // Ball is too fast!
  772.                             factor=max_kp_margin;
  773.                             keeper_will_save=FALSE;
  774.                             player->tm_fstep=MC_BHEADC_FS*factor*keeper_spd;
  775.                         }
  776.                         else
  777.                              player->tm_fstep=keeper_contact/bp;
  778.  
  779.                         if (player->tm_fstep>=1)
  780.                             player->tm_fstep=1;
  781.  
  782.                         save_block=FALSE;
  783.                         init_save_act(player,x,y,z,MC_BHEADCL,zone,bp,(int)(SAVE_BHEADC_TIME/keeper_spd));
  784.                     }
  785.                     else
  786. // Move to best position...
  787.                     {
  788.                         shot_acknowledged=1;
  789.                     }
  790.             }
  791.             else
  792.                 if (z<SAVE_JUMP_HGT)
  793. // Above head level...
  794.                 {
  795.                      if (bp<=SAVE_BJUMPB_TIME/keeper_spd && !keep_dive)
  796.                     {
  797.                         keeper_contact=MCC_BJUMPB;
  798.                         factor=1./((float)bp/(SAVE_BJUMPB_TIME/keeper_spd));
  799.                         if (factor>max_kp_margin && !forced)
  800.                         {
  801. // Ball is too fast!
  802.                             factor=max_kp_margin;
  803.                             keeper_will_save=FALSE;
  804.                             player->tm_fstep=MC_BJUMPB_FS*factor*keeper_spd;
  805.                         }
  806.                         else
  807.                              player->tm_fstep=keeper_contact/bp;
  808.  
  809.                         if (player->tm_fstep>=1)
  810.                             player->tm_fstep=1;
  811.  
  812.                         save_block=TRUE;
  813.                         init_save_act(player,x,y,z,MC_BJUMPBL,zone,bp,(int)(SAVE_BJUMPB_TIME/keeper_spd));
  814.                     }
  815.                     else
  816. // Move to best position...
  817.                     {
  818.                         shot_acknowledged=1;
  819.                     }
  820.                 }
  821. }
  822.  
  823. /******************************************************************************
  824. *****************************************************************************/
  825.  
  826. void save_in_zone_c(match_player *player,float x,float y,float z,int bp,char forced)
  827. {
  828.     float factor;
  829.     keeper_will_save=TRUE;
  830.     keeper_on_grnd=FALSE;
  831.     int zone=3;
  832.     if (z<SAVE_FEET_HGT)
  833. // Feet level...
  834.     {
  835.         if (bp<=SAVE_CFOOTB_TIME/keeper_spd && !keep_dive)
  836.         {
  837.             keeper_contact=MCC_CFOOTB;
  838.             factor=1./((float)bp/(SAVE_CFOOTB_TIME/keeper_spd));
  839.             if (factor>max_kp_margin && !forced)
  840.             {
  841. // Ball is too fast!
  842.                 factor=max_kp_margin;
  843.                 keeper_will_save=FALSE;
  844.                 player->tm_fstep=MC_CFOOTB_FS*factor*keeper_spd;
  845.             }
  846.             else
  847.                 player->tm_fstep=keeper_contact/bp;
  848.  
  849.             if (player->tm_fstep>=1)
  850.                 player->tm_fstep=1;
  851.  
  852.             save_block=TRUE;
  853.             keeper_on_grnd=TRUE;
  854.             init_save_act(player,x,y,z,MC_CFOOTBL,zone,bp,(int)(SAVE_CFOOTB_TIME/keeper_spd));
  855.         }
  856.         else
  857.             if (bp<=SAVE_CFOOTC_TIME/keeper_spd || keep_dive)
  858.             {
  859.                 keeper_contact=MCC_CFOOTC;
  860.                 factor=1./((float)bp/(SAVE_CFOOTC_TIME/keeper_spd));
  861.                 if (factor>max_kp_margin && !forced)
  862.                 {
  863. // Ball is too fast!
  864.                     factor=max_kp_margin;
  865.                     keeper_will_save=FALSE;
  866.                     player->tm_fstep=MC_CFOOTC_FS*factor*keeper_spd;
  867.                 }
  868.                 else
  869.                     player->tm_fstep=keeper_contact/bp;
  870.  
  871.                 if (player->tm_fstep>=1)
  872.                     player->tm_fstep=1;
  873.  
  874.                 save_block=FALSE;
  875.                 keeper_on_grnd=TRUE;
  876.                 init_save_act(player,x,y,z,MC_CFOOTCL,zone,bp,(int)(SAVE_CFOOTC_TIME/keeper_spd));
  877.             }
  878.             else
  879. // Move to best position...
  880.             {
  881.                 shot_acknowledged=1;
  882.             }
  883.     }
  884.     else
  885.         if (z<SAVE_CHEST_HGT)
  886. // Chest level...
  887.         {
  888.              if (bp<=SAVE_CBODYB_TIME/keeper_spd && !keep_dive)
  889.             {
  890.                 keeper_contact=MCC_CBODYB;
  891.                 factor=1./((float)bp/(SAVE_CBODYB_TIME/keeper_spd));
  892.                 if (factor>max_kp_margin && !forced)
  893.                 {
  894. // Ball is too fast!
  895.                     factor=max_kp_margin;
  896.                     keeper_will_save=FALSE;
  897.                     player->tm_fstep=MC_CBODYB_FS*factor*keeper_spd;
  898.                 }
  899.                 else
  900.                     player->tm_fstep=keeper_contact/bp;
  901.  
  902.                 if (player->tm_fstep>=1)
  903.                     player->tm_fstep=1;
  904.  
  905.                 save_block=TRUE;
  906.                 keeper_on_grnd=TRUE;
  907.                 init_save_act(player,x,y,z,MC_CBODYBL,zone,bp,(int)(SAVE_CBODYB_TIME/keeper_spd));
  908.             }
  909.             else
  910.                  if (bp<=SAVE_CBODYC_TIME/keeper_spd || keep_dive)
  911.                 {
  912.                     keeper_contact=MCC_CBODYC;
  913.                     factor=1./((float)bp/(SAVE_CBODYC_TIME/keeper_spd));
  914.                     if (factor>max_kp_margin && !forced)
  915.                     {
  916. // Ball is too fast!
  917.                         factor=max_kp_margin;
  918.                         keeper_will_save=FALSE;
  919.                         player->tm_fstep=MC_CBODYC_FS*factor*keeper_spd;
  920.                     }
  921.                     else
  922.                         player->tm_fstep=keeper_contact/bp;
  923.  
  924.                     if (player->tm_fstep>=1)
  925.                         player->tm_fstep=1;
  926.  
  927.                     save_block=FALSE;
  928.                     keeper_on_grnd=TRUE;
  929.                     init_save_act(player,x,y,z,MC_CBODYCL,zone,bp,(int)(SAVE_CBODYC_TIME/keeper_spd));
  930.                 }
  931.                 else
  932. // Move to best position...
  933.                 {
  934.                     shot_acknowledged=1;
  935.                 }
  936.         }
  937.         else
  938.             if (z<SAVE_HEAD_HGT)
  939. // Head level...
  940.             {
  941.                  if (bp<=SAVE_CHEADB_TIME/keeper_spd && !keep_dive)
  942.                 {
  943.                     keeper_contact=MCC_CHEADB;
  944.                     factor=1./((float)bp/(SAVE_CHEADB_TIME/keeper_spd));
  945.                     if (factor>max_kp_margin && !forced)
  946.                     {
  947. // Ball is too fast!
  948.                         factor=max_kp_margin;
  949.                         keeper_will_save=FALSE;
  950.                         player->tm_fstep=MC_CHEADB_FS*factor*keeper_spd;
  951.                     }
  952.                     else
  953.                         player->tm_fstep=keeper_contact/bp;
  954.  
  955.                     if (player->tm_fstep>=1)
  956.                         player->tm_fstep=1;
  957.  
  958.                     save_block=TRUE;
  959.                     init_save_act(player,x,y,z,MC_CHEADBL,zone,bp,(int)(SAVE_CHEADB_TIME/keeper_spd));
  960.                 }
  961.                 else
  962. // Move to best position...
  963.                 {
  964.                     shot_acknowledged=1;
  965.                 }
  966.             }
  967.             else
  968.                 if (z<SAVE_JUMP_HGT)
  969. // Above head level...
  970.                 {
  971.                      if (bp<=SAVE_CJUMPB_TIME/keeper_spd || keep_dive)
  972.                     {
  973.                         keeper_contact=MCC_CJUMPB;
  974.                         factor=1./((float)bp/(SAVE_CJUMPB_TIME/keeper_spd));
  975.                         if (factor>max_kp_margin && !forced)
  976.                         {
  977. // Ball is too fast!
  978.                             factor=max_kp_margin;
  979.                             keeper_will_save=FALSE;
  980.                             player->tm_fstep=MC_CJUMPB_FS*factor*keeper_spd;
  981.                         }
  982.                         else
  983.                             player->tm_fstep=keeper_contact/bp;
  984.  
  985.                         if (player->tm_fstep>=1)
  986.                             player->tm_fstep=1;
  987.  
  988.                         save_block=TRUE;
  989.                         init_save_act(player,x,y,z,MC_CJUMPBL,zone,bp,(int)(SAVE_CJUMPB_TIME/keeper_spd));
  990.                     }
  991.                     else
  992. // Move to best position...
  993.                     {
  994.                         shot_acknowledged=1;
  995.                     }
  996.                 }
  997. }
  998.  
  999. /******************************************************************************
  1000. *****************************************************************************/
  1001.  
  1002. // Send keeper to point between centre of goal and ball!
  1003. // Point ratio between goal and ball varies with distance to ball.
  1004. // i.e. If opponent is close then point will be further from goal.
  1005.  
  1006. void close_angle(match_player *player,float d,float &x,float &y)
  1007. {
  1008.     float gx,gd,cd;
  1009.  
  1010.     cd=CLOSE_ANG_DIST+(prat*player->tm_vis)/8;
  1011.  
  1012.     if (player->tm_player<12)
  1013. // Keeper A...
  1014.         gx=0;
  1015.     else
  1016. // Keeper B...
  1017.         gx=pitch_len;
  1018.  
  1019.     gd=prat+(d*((cd-d)/cd));    //    How far target point is along line.
  1020.     x=gx+((ballx-gx)*gd/d);
  1021.     y=cntspot_y+((bally-cntspot_y)*gd/d);
  1022. }
  1023.  
  1024. /******************************************************************************
  1025. *****************************************************************************/
  1026.  
  1027. char target_towards_ball(float tx,float ty,float px,float py)
  1028. {
  1029. // Get distance of target to present ball pos.
  1030.     float d=calc_dist(tx-ballx,ty-bally);
  1031.  
  1032.     if (d<=calc_dist(px-ballx,py-bally))
  1033.         return(TRUE);        // Player is further from ball than target!
  1034.  
  1035.     return(FALSE);
  1036. }
  1037.  
  1038. /******************************************************************************
  1039. *****************************************************************************/
  1040.  
  1041. void init_user_save(match_player *player)
  1042. {
  1043.     int t;
  1044.     float dist=prat*1.4;
  1045.     keeper_will_save=FALSE;
  1046.     save_block=TRUE;
  1047.     reset_ideas(player);
  1048.  
  1049.     if (save_direction)
  1050.     {
  1051. // Direction selected...
  1052.         if (save_direction>0)
  1053.         {
  1054. // Raw Left...
  1055.             if (match_mode==PEN_KICK_A)
  1056.             {
  1057. // Dive Right and Up-field...
  1058.                 init_anim(player,MC_CBODYBR);
  1059.                 t=(SAVE_BBODYB_TIME/keeper_spd);
  1060.                 dist=-dist;
  1061.             }
  1062.             else
  1063.             {
  1064. // Dive Right and Down-field...
  1065.                 init_anim(player,MC_CBODYBR);
  1066.                 t=(SAVE_BBODYB_TIME/keeper_spd);
  1067.             }
  1068.         }
  1069.         else
  1070.         {
  1071. // Raw Right...
  1072.             if (match_mode==PEN_KICK_A)
  1073.             {
  1074. // Dive Left and Down-field...
  1075.                 init_anim(player,MC_CBODYBL);
  1076.                 t=(SAVE_BBODYB_TIME/keeper_spd);
  1077.             }
  1078.             else
  1079.             {
  1080. // Dive Left and Up-field...
  1081.                 init_anim(player,MC_CBODYBL);
  1082.                 t=(SAVE_BBODYB_TIME/keeper_spd);
  1083.                 dist=-dist;
  1084.             }
  1085.         }
  1086.     }
  1087.     else
  1088.     {
  1089.         init_anim(player,MC_ABODYB);
  1090.         t=(SAVE_ABODYB_TIME/keeper_spd);
  1091.         dist=0;
  1092.     }
  1093.  
  1094.     player->go_tx=player->tm_x;
  1095.     player->go_ty=player->tm_y+dist;
  1096.     player->go_txdis=0;
  1097.     player->go_tydis=dist/t;
  1098.     player->go_cnt=1/player->tm_fstep;
  1099.     player->dir_mode=5;
  1100.     player->tm_zdis=0;
  1101.     if (keeper_on_grnd)
  1102. // Stay down for a bit after save...
  1103.         if (save_block)
  1104.             player->int_cnt=4+((128-player->tm_rate)/12)+1/player->tm_fstep;        // Time to get up!
  1105.         else
  1106.             player->int_cnt=18+1/player->tm_fstep;        // Time to get up!
  1107.     else
  1108.         player->int_cnt=2+1/player->tm_fstep;
  1109.  
  1110.     player->int_move=I_SAVE_WAIT;
  1111.     action="Save";
  1112.     player->tm_act=SAVE_ACT;
  1113.     newdx=player->tm_xdis;
  1114.     newdy=player->tm_ydis;
  1115. }
  1116.  
  1117. /******************************************************************************
  1118. *****************************************************************************/
  1119.  
  1120. #define DIVE_POINT 3
  1121. #define DIVE_FEET_DIST (prat*4)
  1122.  
  1123. // Someone has shot...
  1124. // Send keeper to intersection with ball path.
  1125. // If he cannot meet ball then best try!
  1126.  
  1127. void go_to_save_path(match_player *player,char forced=FALSE)
  1128. {
  1129.     keeper_spd=((float)(player->tm_flair+player->tm_rate)/128)*(forced ? 2:1);
  1130.  
  1131. // Calculate next frame distance to the ball...
  1132.     float d=calc_dist(player->tm_x-(ballx+ballxdis),player->tm_y-(bally+ballydis));
  1133.  
  1134.     if (!forced)
  1135.     {
  1136.         if (d<player->tm_dist)
  1137. // Ball is getting closer...
  1138.         {
  1139.             if (player->tm_player==KP_A)
  1140.             {
  1141. // Keeper A
  1142.                 if (ballx<cntspot_x)
  1143.                     shot_acknowledged=1+((128-player->tm_vis)/8);
  1144.             }
  1145.             else
  1146.             {
  1147. // Keeper B
  1148.                 if (ballx>cntspot_x)
  1149.                     shot_acknowledged=1+((128-player->tm_vis)/8);
  1150.             }
  1151.         }
  1152.     }
  1153.  
  1154.     if (shot_acknowledged || forced)
  1155.     {
  1156.         int flag;
  1157.         int vision=((128-player->tm_vis)/2);
  1158.  
  1159. // Is shot on Target?
  1160. //    if (ABS(ballxdis)>0)
  1161.         {
  1162.             float kp_xoff;
  1163.             float x,y,z,ox,oy,oz;
  1164.             float xc,yc,zc;
  1165.             float xf,yf,zf;
  1166.             float xns,yns,zns;
  1167.             int bp,ob;
  1168.             float min_d=2000;
  1169.             float d,t,fd;
  1170.             float px=player->tm_x;
  1171.             float py=player->tm_y;
  1172.             float rate=actual_spd(player);    // Dive is 2 x rate.
  1173.             flag=FALSE;
  1174.             char in_area=FALSE;
  1175.  
  1176.             bp=1;
  1177.             ob=1;
  1178.             ox=ballx;
  1179.             oy=bally;
  1180.             oz=ballz;
  1181.             xc=ballx;
  1182.             yc=bally;
  1183.             zc=ballz;
  1184.             
  1185.             if (!keep_dive)
  1186.             {
  1187.                 float see_swerve;
  1188.  
  1189.                 see_swerve=(64.+(player->tm_vis/2))/128;
  1190.  
  1191.                 for (int i=1; i<50; i++)
  1192.                 {
  1193. // Coords without swerve...
  1194.                     xns=ns_ball_pred_tab[i][0];
  1195.                     yns=ns_ball_pred_tab[i][1];
  1196.                     zns=ns_ball_pred_tab[i][2];
  1197.  
  1198. // Coords with swerve...
  1199.                     x=ball_pred_tab[i][0];
  1200.                     y=ball_pred_tab[i][1];
  1201.                     z=ball_pred_tab[i][2];
  1202.  
  1203. // Coords seeing some swerve...
  1204.                     x=xns+((x-xns)*see_swerve);
  1205.                     y=yns+((y-yns)*see_swerve);
  1206.                     z=zns+((z-zns)*see_swerve);
  1207.  
  1208.                     in_area=FALSE;
  1209.  
  1210.                     if (y>top_post_y && y<bot_post_y)
  1211.                         kp_xoff=4;
  1212.                     else
  1213.                         kp_xoff=0;
  1214. // Try and stop keeper saving and carrying ball behind line...
  1215.  
  1216.                     if (x>cntspot_x)
  1217.                     {
  1218. // Team B goal-line...
  1219.                         if (x>=pitch_len-kp_xoff)
  1220.                         {
  1221.                             i=60;
  1222.                             if (ABS(y-cntspot_y)>((prat*4.5)+(128-player->tm_flair)/4))
  1223. // Too wide!
  1224.                                     flag=FALSE;            // Don't bother saving!
  1225.                         }
  1226.                     }
  1227.         
  1228.                     if (x<=cntspot_x)
  1229.                     {
  1230. // Team A goal-line...
  1231.                         if (x<0+kp_xoff)
  1232.                         {
  1233.                             i=60;
  1234.                             if (ABS(y-cntspot_y)>((prat*4.5)+(128-player->tm_flair)/4))
  1235. // Too wide!
  1236.                                 flag=FALSE;            // Don't bother saving!
  1237.                         }
  1238.                     }
  1239.  
  1240.                     if (i!=60)
  1241.                     {
  1242.                         if (player->tm_player<12)
  1243.                         {
  1244.                             if (x<prat*18 && y>cntspot_y-(21*prat)
  1245.                                 && (y<cntspot_y+(21*prat)))
  1246.                                 in_area=TRUE;
  1247.                         }
  1248.                         else
  1249.                         {
  1250.                             if (x>pitch_len-(prat*18) && y>cntspot_y-(21*prat)
  1251.                                 && (y<cntspot_y+(21*prat)))
  1252.                                 in_area=TRUE;
  1253.                         }
  1254.     
  1255.                         if (in_area)
  1256.                         {
  1257.                             d=calc_dist(x-px,y-py);
  1258. //                              if (d<min_d && z<SAVE_JUMP_HGT+prat && target_towards_ball(x,y,px,py))
  1259.                               if (d<min_d && z<SAVE_JUMP_HGT+prat/2)
  1260. // Store closest ball!
  1261.                               {
  1262.                                 ox=xc;
  1263.                                 oy=yc;
  1264.                                 oz=zc;
  1265.                                 ob=bp;
  1266.                                   min_d=d;
  1267.                                   bp=i;
  1268.                                 xc=x;
  1269.                                 yc=y;
  1270.                                 zc=z;
  1271.                                 flag=TRUE;
  1272.                             }
  1273.                             else
  1274. // Getting further away...
  1275.                             {
  1276.                                 if (d-min_d>prat)
  1277. // Definately not getting any closer...
  1278.                                 {
  1279.                                     i=60;            // Quit.
  1280.                                 }
  1281.                             }
  1282.                         }
  1283.                     }
  1284.                 }
  1285.             }
  1286.  
  1287.             else
  1288.             {
  1289.                 flag=TRUE;
  1290.                 xc=ball_pred_tab[DIVE_POINT][0];
  1291.                 yc=ball_pred_tab[DIVE_POINT][1];
  1292.                 zc=ball_pred_tab[DIVE_POINT][2];
  1293.                 d=calc_dist(xc-px,yc-py);
  1294.                 x=(xc-px)/d;
  1295.                 y=(yc-py)/d;
  1296.                 if (keep_dive)
  1297.                 {
  1298.                     xc+=x*prat;
  1299.                     yc+=y*prat;
  1300.                 }
  1301.                 ox=xc;
  1302.                 oy=yc;
  1303.                 oz=zc;
  1304.                 ob=DIVE_POINT;
  1305.                 bp=DIVE_POINT;
  1306.             }
  1307.  
  1308.             if (flag)
  1309. // Shot is in area...
  1310.             {
  1311.                 x=ox+((xc-ox)/2);        // Between closest and one before...
  1312.                 y=oy+((yc-oy)/2);
  1313.                 z=oz+((zc-oz)/2);
  1314.  
  1315.                 if (forced)            // Forced to dive at attackers feet...
  1316.                 {
  1317.                     fd=calc_dist(x-px,y-py);
  1318.                     xf=(x-px)/fd;
  1319.                     yf=(y-py)/fd;
  1320.                     x+=xf*3;
  1321.                     y+=yf*3;        // Dive beyond point of contact...
  1322.                 }
  1323.  
  1324. //                bp=ob;
  1325.  
  1326. // Nearest ball coord.
  1327.  
  1328.                 d=calc_dist(x-px,y-py);        // Distance to keeper...
  1329.       
  1330.                 char st=player->go_step;
  1331.                 player->go_step=TRUE;
  1332.                 t=d/actual_spd(player);    // Time to step there...
  1333.                 player->go_step=st;
  1334.  
  1335.                 max_kp_margin=1.5+(1.8*time_factor/90);
  1336.  
  1337. /*************************************************************/
  1338. /*************************************************************/
  1339. #ifdef EURO96
  1340.                 if (penalty_shot && user_controlled)
  1341.                 {
  1342.                     if (users_dir[user_controlled-1].f&8)
  1343.                         save_direction=-1;
  1344.                     if (users_dir[user_controlled-1].f&4)
  1345.                         save_direction=1;
  1346.  
  1347.                     char good_choice=FALSE;
  1348. // User decides which way to dive...
  1349.                     if (t<1 && !save_direction)
  1350.                     {
  1351. // Straight on...(good choice!)
  1352.                         good_choice=TRUE;
  1353.                     }
  1354.                     else
  1355.                     {
  1356.                         if (save_direction)
  1357.                         {
  1358. // User has chosen a direction...
  1359.                             if (save_direction<0)
  1360.                             {
  1361. // Left selected...
  1362.                                 if ((x<cntspot_x && player->tm_y>(y+(SAVE_ZONE_A/2)))
  1363.                                     || (x>cntspot_x && player->tm_y<(y-(SAVE_ZONE_A/2))))
  1364.                                 {
  1365.                                     good_choice=TRUE;
  1366.                                 }
  1367.                             }
  1368.                             else
  1369.                             {
  1370. // Right selected...
  1371.                                 if ((x<cntspot_x && player->tm_y<(y-(SAVE_ZONE_A/2)))
  1372.                                     || (x>cntspot_x && player->tm_y>(y+(SAVE_ZONE_A/2))))
  1373.                                 {
  1374.                                     good_choice=TRUE;
  1375.                                 }
  1376.                             }
  1377.                         }
  1378.                         else
  1379.                        {
  1380.                             if (d<=SAVE_ZONE_A)
  1381.                                 good_choice=TRUE;
  1382.                         }
  1383.                     }
  1384.  
  1385.                     if (good_choice)
  1386.                     {
  1387. // Let computer save...
  1388.                         if (t<1)
  1389.                         {
  1390.                             save_in_zone_a(player,x,y,z,bp,forced);
  1391.                         }
  1392.                         else
  1393.                         {
  1394.                             if (d<=SAVE_ZONE_A)
  1395.                                 save_in_zone_a(player,x,y,z,bp,forced);
  1396.                             else
  1397.                                 if (d<=SAVE_ZONE_B)
  1398.                                     save_in_zone_b(player,x,y,z,bp,forced);
  1399.                                 else
  1400.                                     if (d<=(SAVE_ZONE_C+prat*2))
  1401.                                         save_in_zone_c(player,x,y,z,bp,forced);
  1402.                                     else
  1403.                                         keep_dive=FALSE;
  1404.                         }
  1405.                     }
  1406.                     else
  1407.                     {
  1408. // Save in the direction of user's choice...
  1409.                         init_user_save(player);
  1410.                     }
  1411.                 }
  1412.                 else
  1413. #endif
  1414. /*************************************************************/
  1415. /*************************************************************/
  1416.                 {
  1417.                     if (t<1)
  1418. /************************************/
  1419. // Already in preferred position... //
  1420. /************************************/
  1421.  
  1422.                     {
  1423.                         save_in_zone_a(player,x,y,z,bp,forced);
  1424.                     }
  1425.                     else
  1426.                     {
  1427.  
  1428.                         if (t<bp-SAVE_AHEADC_TIME)
  1429. /************************************************************/
  1430. // Can get body behind it and still have time to animate... //
  1431. /************************************************************/
  1432.                         {
  1433.                             reset_ideas(player);
  1434.                             player->go_step=TRUE;
  1435.                             if (player->tm_player<12)
  1436.                                 init_run_act(player,x-prat,y,TRUE);            //ball meet point
  1437.                             else
  1438.                                 init_run_act(player,x+prat,y,TRUE);            //ball meet point
  1439.                         }
  1440.                         else
  1441.                         {
  1442.                             if (d<=SAVE_ZONE_A)
  1443.                                 save_in_zone_a(player,x,y,z,bp,forced);
  1444.                             else
  1445.                                 if (d<=SAVE_ZONE_B)
  1446.                                     save_in_zone_b(player,x,y,z,bp,forced);
  1447.                                 else
  1448.                                     if (d<=(SAVE_ZONE_C+prat*2))
  1449.                                         save_in_zone_c(player,x,y,z,bp,forced);
  1450.                                     else
  1451.                                         keep_dive=FALSE;
  1452.                         }
  1453.                     }
  1454.                 }
  1455.             }
  1456.         }
  1457.     }
  1458. }
  1459.  
  1460. /******************************************************************************
  1461. *****************************************************************************/
  1462.  
  1463. void fake_ball_poss(int p,float x,float y,float z)
  1464. {
  1465.     save_ball_poss=ball_poss;
  1466.     save_ballx=ballx;
  1467.     save_bally=bally;
  1468.     save_ballz=ballz;
  1469.     ballx=x;
  1470.     bally=y;
  1471.     ballz=z;
  1472.     ball_poss=p;
  1473. }
  1474.  
  1475. /******************************************************************************
  1476. *****************************************************************************/
  1477.  
  1478. void restore_ball_poss()
  1479. {
  1480.     ball_poss=save_ball_poss;
  1481.     ballx=save_ballx;
  1482.     bally=save_bally;
  1483.     ballz=save_ballz;
  1484. }
  1485.  
  1486. /******************************************************************************
  1487. *****************************************************************************/
  1488.  
  1489. char kick_straight()
  1490. {
  1491.      if (pass_type==-1 || (pass_type>=4 && pass_type<=6))
  1492.         return(TRUE);
  1493.     else
  1494.         return(FALSE);
  1495. }
  1496.  
  1497. /******************************************************************************
  1498. *****************************************************************************/
  1499.  
  1500. char first_time_strike(int p,float x,float y,float z,float px,float py)
  1501. {
  1502.     float d;
  1503.     float obx=ballx;
  1504.     float oby=bally;
  1505.  
  1506.     char sr=teams[p-1].tm_srng;
  1507.     if (p<12)
  1508.         d=calc_dist(pitch_len-x,cntspot_y-y);
  1509.     else
  1510.         d=calc_dist(x,cntspot_y-y);
  1511.  
  1512.     if (d<(MIN_SHOOT_DIST+((float)teams[p-1].tm_pow*3)))
  1513.         teams[p-1].tm_srng=TRUE;
  1514.     else
  1515.         teams[p-1].tm_srng=FALSE;
  1516.  
  1517.     float xpd=teams[p-1].tm_xdis;
  1518.     float ypd=teams[p-1].tm_ydis;
  1519.     teams[p-1].tm_xdis=x_face;
  1520.     teams[p-1].tm_ydis=y_face;
  1521.     ballx=teams[p-1].tm_x;
  1522.     bally=teams[p-1].tm_y;
  1523.     
  1524.     pass_type=FALSE;
  1525.     receiver=FALSE;
  1526.     char allow=0;
  1527.     float gx,gy;
  1528.  
  1529.     if (p<12)
  1530.         gx=pitch_len;
  1531.     else
  1532.         gx=0;
  1533.  
  1534.     gy=cntspot_y;
  1535.     gx-=x;
  1536.     gy-=y;
  1537.     d=calc_dist(gx,gy);
  1538.  
  1539.     fake_ball_poss(p,x,y,z);
  1540.  
  1541.     if (auto_select)
  1542.     {
  1543.         if (ball_int_speed>6)
  1544.         {
  1545. // Ball is moving so he can trap...
  1546.             allow=128;        // Can control it...
  1547.         }
  1548.  
  1549.         if (shoot_decide(&teams[p-1]))
  1550.         {
  1551.             pass_type=0;
  1552.             allow+=3;                    // Kick or volley!
  1553.             if (d<MIN_HEADER_RNG+(prat*teams[p-1].tm_pow/8))
  1554. // In head range also!
  1555.             {
  1556.                 allow+=8+16;            // Standing or Jumping header!
  1557.                 if (kick_straight())
  1558. // Target is forward!
  1559.                     allow+=4;            // Diving header!
  1560.             }
  1561.         }
  1562.         else
  1563.         {
  1564.             teams[p-1].tm_xdis=-teams[p-1].tm_xdis;
  1565.             teams[p-1].tm_ydis=-teams[p-1].tm_ydis;        // Reverse face!
  1566.  
  1567.             if (shoot_decide(&teams[p-1]))
  1568.             {
  1569.                 pass_type=0;
  1570.                 allow+=32;                // Overhead!
  1571.             }
  1572.             else
  1573.             {
  1574.                 if (punt_decide(&teams[p-1]))    // Overhead punt???
  1575.                 {
  1576.                     pass_type=0;
  1577.                     allow+=32;                // Overhead!
  1578.                 }
  1579.                 else
  1580.                 {
  1581.                     teams[p-1].tm_xdis=-teams[p-1].tm_xdis;
  1582.                     teams[p-1].tm_ydis=-teams[p-1].tm_ydis;        // Reverse face!
  1583.                     if (punt_decide(&teams[p-1]))
  1584.                     {
  1585.                         pass_type=0;
  1586.                         allow+=1+2+4+8+16;                        // Kick or volley or any header!
  1587.                     }
  1588.                     else
  1589.                     {
  1590.                         receiver=pass_decide(&teams[p-1],FALSE);
  1591.                         if (receiver)
  1592.                         {
  1593.                             if (pass_type==-1)
  1594. // Chip pass!
  1595.                                 allow+=64+8+16;        // Chip, S-head, J-head!
  1596.                             else
  1597.                             {
  1598.                                 if (kick_straight())
  1599.                                     allow+=8+16;        // S-head, J-head!
  1600.                             }
  1601.                         }
  1602.                     }
  1603.                 }
  1604.             }
  1605.         }
  1606.     }
  1607.     else
  1608.         allow=0;
  1609.  
  1610.     restore_ball_poss();
  1611.  
  1612.     teams[p-1].tm_srng=sr;            // Restore range flag!
  1613.     teams[p-1].tm_xdis=xpd;
  1614.     teams[p-1].tm_ydis=ypd;
  1615.     ballx=obx;
  1616.     bally=oby;
  1617.  
  1618.     return(allow);
  1619. }
  1620.  
  1621. /******************************************************************************
  1622. *****************************************************************************/
  1623.  
  1624. char user_pass_check(int p,float x,float y,float z,float px,float py)
  1625. {
  1626.     float d;
  1627.     float obx=ballx;
  1628.     float oby=bally;
  1629.  
  1630.     char sr=teams[p-1].tm_srng;
  1631.     if (p<12)
  1632.         d=calc_dist(pitch_len-x,cntspot_y-y);
  1633.     else
  1634.         d=calc_dist(x,cntspot_y-y);
  1635.  
  1636.     if (d<(MIN_SHOOT_DIST+((float)teams[p-1].tm_pow*3)))
  1637.         teams[p-1].tm_srng=TRUE;
  1638.     else
  1639.         teams[p-1].tm_srng=FALSE;
  1640.  
  1641.     float xpd=teams[p-1].tm_xdis;
  1642.     float ypd=teams[p-1].tm_ydis;
  1643.     teams[p-1].tm_xdis=x_face;
  1644.     teams[p-1].tm_ydis=y_face;
  1645.     ballx=teams[p-1].tm_x;
  1646.     bally=teams[p-1].tm_y;
  1647.     
  1648.     pass_type=FALSE;
  1649.     receiver=FALSE;
  1650.     char allow=0;
  1651.     float gx,gy;
  1652.  
  1653.     if (p<12)
  1654.         gx=pitch_len;
  1655.     else
  1656.         gx=0;
  1657.  
  1658.     gy=cntspot_y;
  1659.     gx-=x;
  1660.     gy-=y;
  1661.     d=calc_dist(gx,gy);
  1662.  
  1663.     fake_ball_poss(p,x,y,z);
  1664.  
  1665.     receiver=pass_decide(&teams[p-1],FALSE);
  1666.     if (receiver)
  1667.     {
  1668.         if (pass_type==-1)
  1669. // Chip pass!
  1670.             allow+=64+8+16;        // Chip, S-head, J-head!
  1671.         else
  1672.         {
  1673.             if (kick_straight())
  1674.                 allow+=8+16;        // S-head, J-head!
  1675.         }
  1676.     }
  1677.     else
  1678.         allow=0;
  1679.  
  1680.     restore_ball_poss();
  1681.  
  1682.     teams[p-1].tm_srng=sr;            // Restore range flag!
  1683.     teams[p-1].tm_xdis=xpd;
  1684.     teams[p-1].tm_ydis=ypd;
  1685.     ballx=obx;
  1686.     bally=oby;
  1687.  
  1688.     return(allow);
  1689. }
  1690.  
  1691.  
  1692. /******************************************************************************
  1693. *****************************************************************************/
  1694.  
  1695. void decide_strike(match_player *p,short t,char c,char s)
  1696. {
  1697.     float x=ball_pred_tab[t][0];
  1698.     float y=ball_pred_tab[t][1];
  1699.     float z=ball_pred_tab[t][1];
  1700.  
  1701.     p->int_cnt=t;                        // Flair factor.
  1702.     init_run_act(p,x,y,TRUE);
  1703.     p->tm_strike=TRUE;
  1704. }
  1705.  
  1706. /******************************************************************************
  1707. *****************************************************************************/
  1708.  
  1709. void strike_and_control(match_player *player,intercept_data *s,short action)
  1710. {
  1711.     player->tm_stime=s->atime+1;
  1712.  
  1713. //    player->int_cnt=player->tm_stime+alarm+free+1;    // Make sure he seems busy for the duration!
  1714.  
  1715.     float x=s->x;
  1716.     float y=s->y;
  1717.  
  1718.     switch(action)
  1719.     {
  1720.         case(7):
  1721.         case(9):
  1722.         case(10):
  1723.             if (player->tm_fpass_type=s->ptype)
  1724. // Equate pass type and test!
  1725.                 player->tm_fpass_to=s->pplr;
  1726.             break;
  1727.     }
  1728.  
  1729.     short gt=get_there_time(player->tm_player,x,y);
  1730.  
  1731.     player->tm_ftime=s->free;
  1732.     player->tm_strike=action;
  1733.     init_run_act(player,x,y,FALSE);
  1734.  
  1735.     player->int_cnt=player->go_cnt+player->tm_ftime+player->tm_stime;
  1736.     if (must_face)
  1737.         player->int_cnt+=player->mface_time;
  1738.  
  1739.     if (user_controlled)
  1740.     {
  1741.         player->special=-TRUE;        // Special action decided!
  1742. /*
  1743.         if (player->go_cnt>1)
  1744.         {
  1745.             player->go_cnt=1;
  1746.             player->int_cnt=1;
  1747.         }
  1748. */
  1749.     }
  1750. }
  1751.  
  1752. /******************************************************************************
  1753. *****************************************************************************/
  1754.  
  1755. void cancel_int(int p)
  1756. {
  1757. // should never get here!
  1758.     init_stand_act(&teams[p-1]);
  1759. }
  1760.  
  1761. /******************************************************************************
  1762. *****************************************************************************/
  1763.  
  1764. void intercept(int p)
  1765. {
  1766.     action="Intercept";
  1767.  
  1768.     reset_ideas(&teams[p-1]);
  1769.  
  1770.     if (p<12)
  1771.         interceptor_a=p;
  1772.     else
  1773.         interceptor_b=p;
  1774.  
  1775. // His intention is to intercept ball.
  1776. // Therefore his flair determines no. of turns before rethink!
  1777.  
  1778.     int ff=33-(teams[p-1].tm_flair/4);
  1779.     teams[p-1].int_move=I_INTERCEPT;        // Intercept ball!
  1780.     teams[p-1].int_cnt=ff;                    // Intercept ball!
  1781.  
  1782.     float x,y;
  1783.  
  1784.     if (special_move)
  1785.          teams[p-1].special=TRUE;
  1786.     else
  1787.          teams[p-1].special=FALSE;
  1788.  
  1789.     {
  1790.         for (short i=10; i>=0; i--)
  1791.         {
  1792.             if (strike[i].t)
  1793.             {
  1794.                 if (i>0)
  1795.                 {
  1796.                     if (user_controlled)
  1797.                     {
  1798. // uf1 = strike, uf2 = control!
  1799.                         if (uf1 && i>4)
  1800.                         {
  1801.                             strike_and_control(&teams[p-1],&strike[i],i);
  1802.                             break;
  1803.                         }
  1804.                         else
  1805.                         {
  1806.                             if (uf2 && i<=4 && i)
  1807.                             {
  1808.                                 strike_and_control(&teams[p-1],&strike[i],i);
  1809.                                 break;
  1810.                             }
  1811.                         }
  1812.                     }
  1813.                     else
  1814.                     {
  1815.                         strike_and_control(&teams[p-1],&strike[i],i);
  1816.                         break;
  1817.                     }
  1818.                 }
  1819.                 else
  1820.                 {
  1821. // Run onto ball...
  1822.                     if (strike[0].stop)
  1823.                         init_stop_act(&teams[p-1],strike[0].x,strike[0].y);
  1824.                     else
  1825.                         init_run_act(&teams[p-1],strike[0].x,strike[0].y,FALSE);
  1826.  
  1827.                     teams[p-1].go_cnt++;
  1828.                     break;
  1829.                 }
  1830.             }
  1831.         }
  1832.     }
  1833. }
  1834.  
  1835. /******************************************************************************
  1836. *****************************************************************************/
  1837.  
  1838. float fstep_factor(short c)
  1839. {
  1840. // Returns a range of 0.6(c=0) to 1.6(c=128)
  1841.     float f=0.6+((float)c/128);
  1842.     return(f);
  1843. }
  1844.  
  1845. /******************************************************************************
  1846. *****************************************************************************/
  1847.  
  1848. #ifdef EURO96
  1849. // Euro 96 has first time pass implemented...
  1850.  
  1851. char can_i_intercept(int p_num,float x,float y,float z,float px,float py,short i)
  1852. {
  1853.     if (z>=teams[p_num-1].tm_jump)
  1854.         return(FALSE);
  1855.  
  1856.     float cx,cy,cz,cx2,cy2,ang;
  1857.     float rate=full_spd(&teams[p_num-1]);
  1858.     float d=calc_dist(x-px,y-py);
  1859.     char can_strike;
  1860.     char do_it=FALSE;
  1861.     char stand;
  1862.     char strike_option=FALSE;
  1863.     char trap_option=FALSE;
  1864.     char pass_option=FALSE;
  1865.  
  1866.     short ff=1+teams[p_num-1].tm_flair/16;        // Reaction times.
  1867.  
  1868.     short gt=get_there_time(p_num,x,y);
  1869.     short t;
  1870.  
  1871.     if (gt<=i)
  1872.     {
  1873. // He can get to ball in time...
  1874.  
  1875.         if (ball_poss)
  1876.         {
  1877. // Opponent has ball... (No control or strike!)
  1878. /***** RUN ONTO BALL *****/
  1879.             t=i-gt;
  1880.             if (t>0 && t<strike[0].free && (teams[p_num-1].control || t<ff))
  1881.             {
  1882.                   strike[0].t=i;
  1883.                   strike[0].free=t;
  1884.                 strike[0].x=x;
  1885.                 strike[0].y=y;
  1886.                 strike[0].stop=stop_and_face;
  1887.                 do_it=TRUE;
  1888.             }
  1889.         }
  1890.         else
  1891.         {
  1892.             if (user_controlled)
  1893.             {
  1894.                 can_strike=128+32+16+8+4+2+1;
  1895.                 pass_type=0;
  1896.                 strike_option=uf1&(!uf2);
  1897.                 trap_option=uf2&(!uf1);
  1898.                 pass_option=uf1&uf2;
  1899.                 if (pass_option)
  1900.                     can_strike=user_pass_check(p_num,x,y,z,px,py);
  1901.             }
  1902.             else
  1903.                 can_strike=first_time_strike(p_num,x,y,z,px,py);
  1904.  
  1905. /***** RUN ONTO BALL *****/
  1906.  
  1907.             if (z<PLAYER_HEIGHT/3)
  1908.             {
  1909. // Feet level...
  1910.                 ang=angle_to_xy(x-px,y-py,teams[p_num-1].tm_xdis,teams[p_num-1].tm_ydis);
  1911.                 if (ang>0 || user_controlled)
  1912.                 {
  1913. // Target is in front of player...
  1914.                     t=i-gt;
  1915.                     if (t>=0 && t<strike[0].free && (teams[p_num-1].control || t<ff))
  1916.                     {
  1917.                           strike[0].t=i;
  1918.                           strike[0].free=t;
  1919.                         strike[0].x=x;
  1920.                         strike[0].y=y;
  1921.                         strike[0].stop=stop_and_face;
  1922.                         do_it=TRUE;
  1923.                     }
  1924.                 }
  1925.             }
  1926.  
  1927. //            if (plr_facing(x-px,y-py,&teams[p_num-1]) && target_towards_ball(x,y,px,py)
  1928. //            if ((target_towards_ball(x,y,px,py) || stop_and_face) &&
  1929. //            if (
  1930. //                 teams[p_num-1].tm_act<=TURN_ACT)
  1931.             
  1932.             if ((p_num!=KP_A && p_num!=KP_B)
  1933.                  || (p_num==KP_A && cannot_pick_up<12) || (p_num==KP_B && cannot_pick_up>11))
  1934.             {
  1935. // Keeper cannot pick ball up...
  1936.  
  1937. // Player must be running or standing...
  1938.  
  1939.                 if (teams[p_num-1].tm_trap>=0)
  1940.                 {
  1941. // Must control ball or may hit it first time...
  1942.  
  1943. /***** TRAP AND CONTROL *****/
  1944.  
  1945.                     if (can_strike&128)
  1946.                     {
  1947.                         if (z<PLAYER_HEIGHT/2)
  1948.                         {
  1949. // Feet level...
  1950.                             rotate_offs(MC_TRAPL,cx,cy,cz,x_face,y_face);
  1951.                             rotate_offs(MC_TRAPR,cx2,cy2,cz,x_face,y_face);
  1952.                             cx=(cx+cx2)/2;
  1953.                             cy=(cy+cy2)/2;
  1954.                             gt=get_there_time(p_num,x-cx,y-cy);
  1955.                             t=i-(gt+ft_ttm);
  1956.                             if (t>=0 && t<strike[1].free && (teams[p_num-1].control || t<ff))
  1957.                             {
  1958. // He has time to animate...
  1959. // Best so far!
  1960.                                 special_move=TRUE;
  1961.                                 if (trap_option || !user_controlled)
  1962.                                 {
  1963.                                       strike[1].t=i;
  1964.                                       strike[1].free=t;
  1965.                                     strike[1].atime=ft_ttm;
  1966.                                       strike[1].gt=gt;
  1967.                                     strike[1].x=x-cx;
  1968.                                     strike[1].y=y-cy;
  1969.                                     strike[1].stop=stop_and_face;
  1970.                                     do_it=TRUE;
  1971.                                 }
  1972.                             }
  1973.                         }
  1974.                         else
  1975.                         {
  1976.                             if (z<(PLAYER_HEIGHT-2))
  1977.                             {
  1978. // Chest level...
  1979.                                 rotate_offs(MC_CHEST,cx,cy,cz,x_face,y_face);
  1980.                                 gt=get_there_time(p_num,x-cx,y-cy);
  1981.                                 t=i-(gt+ft_ctm);
  1982.                                 if (t>=0 && t<strike[2].free && (teams[p_num-1].control || t<ff))
  1983.                                 {
  1984. // He has time to animate...
  1985. // Best so far!
  1986.                                     special_move=TRUE;
  1987.                                     if (trap_option || !user_controlled)
  1988.                                     {
  1989.                                           strike[2].t=i;
  1990.                                           strike[2].free=t;
  1991.                                         strike[2].atime=ft_ctm;
  1992.                                           strike[2].gt=gt;
  1993.                                         strike[2].x=x-cx;
  1994.                                         strike[2].y=y-cy;
  1995.                                         strike[2].stop=stop_and_face;
  1996.                                         do_it=TRUE;
  1997.                                     }
  1998.                                 }
  1999.                             }
  2000.                             else
  2001.                             {
  2002.                                 if (z<(PLAYER_HEIGHT+4))
  2003.                                 {
  2004. // Head level...
  2005.                                     rotate_offs(MC_D_HEAD,cx,cy,cz,x_face,y_face);
  2006.                                     gt=get_there_time(p_num,x-cx,y-cy);
  2007.                                     t=i-(gt+ft_utm);
  2008.                                     if (t>=0 && t<strike[3].free && (teams[p_num-1].control || t<ff))
  2009.                                     {
  2010. // He has time to animate...
  2011. // Best so far!
  2012.                                         special_move=TRUE;
  2013.                                         if (trap_option || !user_controlled)
  2014.                                         {
  2015.                                               strike[3].t=i;
  2016.                                               strike[3].free=t;
  2017.                                             strike[3].atime=ft_utm;
  2018.                                               strike[3].gt=gt;
  2019.                                             strike[3].x=x-cx;
  2020.                                             strike[3].y=y-cy;
  2021.                                             strike[3].stop=stop_and_face;
  2022.                                             do_it=TRUE;
  2023.                                         }
  2024.                                     }
  2025.                                 }
  2026.                             }
  2027.                         }
  2028.                     }
  2029.                 }
  2030.  
  2031.                 if (teams[p_num-1].tm_trap<=0)
  2032.                 {
  2033.     
  2034. // May hit it first time...
  2035.  
  2036. /***** FIRST TIME STRIKE *****/
  2037.  
  2038.                     if (z<PLAYER_HEIGHT/4)
  2039.                     {
  2040.                         if (can_strike&1)
  2041.                         {
  2042. // Feet level...
  2043.                             rotate_offs(MC_SHOOTL,cx,cy,cz,x_face,y_face);
  2044.                             rotate_offs(MC_SHOOTR,cx2,cy2,cz,x_face,y_face);
  2045.                             cx=(cx+cx2)/2;
  2046.                             cy=(cy+cy2)/2;
  2047.                             gt=get_there_time(p_num,x-cx,y-cy);
  2048.                             t=i-(gt+ft_ktm);
  2049.                             if (t>=0 && t<strike[8].free && (teams[p_num-1].control || t<ff))
  2050.                             {
  2051. // He has time to animate...
  2052. // Best so far!
  2053.                                 special_move=TRUE;
  2054.                                 if (strike_option || !user_controlled)
  2055.                                 {
  2056.                                       strike[8].t=i;
  2057.                                       strike[8].free=t;
  2058.                                     strike[8].atime=ft_ktm;
  2059.                                       strike[8].gt=gt;
  2060.                                     strike[8].x=x-cx;
  2061.                                     strike[8].y=y-cy;
  2062.                                     strike[8].stop=stop_and_face;
  2063.                                     do_it=TRUE;
  2064.                                 }
  2065.                             }
  2066.                         }
  2067.  
  2068.                         if (can_strike&64)
  2069.                         {
  2070. // Feet level...
  2071.                             rotate_offs(MC_CHIPL,cx,cy,cz,x_face,y_face);
  2072.                             rotate_offs(MC_CHIPR,cx2,cy2,cz,x_face,y_face);
  2073.                             cx=(cx+cx2)/2;
  2074.                             cy=(cy+cy2)/2;
  2075.                             gt=get_there_time(p_num,x-cx,y-cy);
  2076.                             t=i-(gt+ft_ctm);
  2077.                             if (t>=0 && t<strike[10].free && (teams[p_num-1].control || t<ff))
  2078.                             {
  2079. // He has time to animate...
  2080. // Best so far!
  2081.                                 special_move=TRUE;
  2082.                                 if (strike_option || !user_controlled)
  2083.                                 {
  2084.                                       strike[10].t=i;
  2085.                                       strike[10].free=t;
  2086.                                     strike[10].ptype=pass_type;
  2087.                                     strike[10].pplr=receiver;
  2088.                                     strike[10].atime=ft_ctm;
  2089.                                       strike[10].gt=gt;
  2090.                                     strike[10].x=x-cx;
  2091.                                     strike[10].y=y-cy;
  2092.                                     strike[10].stop=stop_and_face;
  2093.                                     do_it=TRUE;
  2094.                                 }
  2095.                             }
  2096.                         }
  2097.                     }
  2098.                     else
  2099.                     {
  2100.                         if (z<PLAYER_HEIGHT*.5)
  2101.                         {
  2102. // volley level...
  2103.                             if (can_strike&2)
  2104.                             {
  2105.                                 rotate_offs(MC_VOLLEYL,cx,cy,cz,x_face,y_face);
  2106.                                 gt=get_there_time(p_num,x-cx,y-cy);
  2107.                                 t=i-(gt+ft_vtm);
  2108.                                 if (t>=0 && t<strike[5].free && (teams[p_num-1].control || t<ff))
  2109.                                 {
  2110. // He has time to animate...
  2111. // Best so far!
  2112.                                     special_move=TRUE;
  2113.                                     if (strike_option || !user_controlled)
  2114.                                     {
  2115.                                           strike[5].t=i;
  2116.                                           strike[5].free=t;
  2117.                                         strike[5].atime=ft_vtm;
  2118.                                           strike[5].gt=gt;
  2119.                                         strike[5].x=x-cx;
  2120.                                         strike[5].y=y-cy;
  2121.                                         strike[5].stop=stop_and_face;
  2122.                                         do_it=TRUE;
  2123.                                     }
  2124.                                 }
  2125.                             }
  2126.                         }
  2127.                         else
  2128.                         {
  2129.                             if (z<PLAYER_HEIGHT*.67)
  2130.                             {
  2131.                                 if (can_strike&4)
  2132.                                 {
  2133.                                     rotate_offs(MC_DV_HEAD,cx,cy,cz,x_face,y_face);
  2134.                                     gt=get_there_time(p_num,x-cx,y-cy);
  2135.                                     t=i-(gt+ft_dtm);
  2136.                                     if (t>=0 && t<strike[6].free && (teams[p_num-1].control || t<ff))
  2137.                                     {
  2138. // He has time to animate...
  2139. // Best so far!
  2140.                                         special_move=TRUE;
  2141.                                         if (strike_option || !user_controlled)
  2142.                                         {
  2143.                                               strike[6].t=i;
  2144.                                               strike[6].free=t;
  2145.                                             strike[6].atime=ft_dtm;
  2146.                                               strike[6].gt=gt;
  2147.                                             strike[6].x=x-cx;
  2148.                                             strike[6].y=y-cy;
  2149.                                             strike[6].stop=stop_and_face;
  2150.                                             do_it=TRUE;
  2151.                                         }
  2152.                                     }
  2153.                                 }
  2154.                             }
  2155.                             else
  2156.                             {
  2157.                                 if (z<PLAYER_HEIGHT+2)
  2158.                                 {
  2159. // head level...
  2160.                                     if (can_strike&32)
  2161.                                     {
  2162.                                         rotate_offs(MC_OVERHEAD,cx,cy,cz,x_face,y_face);
  2163.                                         gt=get_there_time(p_num,x-cx,y-cy);
  2164.                                         t=i-(gt+ft_otm);
  2165.                                         if (t>=0 && t<strike[4].free && (teams[p_num-1].control || t<ff))
  2166.                                         {
  2167. // He has time to animate...
  2168. // Best so far!
  2169.                                             special_move=TRUE;
  2170.                                             if (strike_option || !user_controlled)
  2171.                                             {
  2172.                                                   strike[4].t=i;
  2173.                                                   strike[4].free=t;
  2174.                                                 strike[4].atime=ft_otm;
  2175.                                                   strike[4].gt=gt;
  2176.                                                 strike[4].x=x-cx;
  2177.                                                 strike[4].y=y-cy;
  2178.                                                 strike[4].stop=stop_and_face;
  2179.                                                 do_it=TRUE;
  2180.                                             }
  2181.                                         }
  2182.                                     }
  2183.  
  2184.                                     if (can_strike&8)
  2185.                                     {
  2186. // He has time...
  2187.                                         rotate_offs(MC_S_HEAD,cx,cy,cz,x_face,y_face);
  2188.                                         gt=get_there_time(p_num,x-cx,y-cy);
  2189.                                         t=i-(gt+ft_stm);
  2190.                                         if (t>=0 && t<strike[9].free && (teams[p_num-1].control || t<ff))
  2191.                                         {
  2192. // He has time to animate...
  2193. // Best so far!
  2194.                                             special_move=TRUE;
  2195.                                             if (strike_option || !user_controlled)
  2196.                                             {
  2197.                                                   strike[9].t=i;
  2198.                                                   strike[9].free=t;
  2199.                                                 strike[9].ptype=pass_type;
  2200.                                                 strike[9].pplr=receiver;
  2201.                                                 strike[9].atime=ft_stm;
  2202.                                                   strike[9].gt=gt;
  2203.                                                 strike[9].x=x-cx;
  2204.                                                 strike[9].y=y-cy;
  2205.                                                 strike[9].stop=stop_and_face;
  2206.                                                 do_it=TRUE;
  2207.                                             }
  2208.                                         }
  2209.                                     }
  2210.                                 }
  2211.                                 else
  2212.                                 {
  2213.                                     if (z<teams[p_num-1].tm_jump)
  2214.                                     {
  2215. // Jump level...
  2216.                                         if (can_strike&16)
  2217.                                         {
  2218. // He has time...
  2219.                                             rotate_offs(MC_J_HEAD,cx,cy,cz,x_face,y_face);
  2220.                                             gt=get_there_time(p_num,x-cx,y-cy);
  2221.                                             t=i-(gt+ft_jtm);
  2222.                                             if (ABS(cz+prat-z)<8 && t>=0 && t<strike[7].free && (teams[p_num-1].control || t<ff))
  2223.                                             {
  2224. // He has time to animate...
  2225. // Best so far!
  2226.                                                 special_move=TRUE;
  2227.                                                 if (strike_option || !user_controlled)
  2228.                                                 {
  2229.                                                       strike[7].t=i;
  2230.                                                       strike[7].free=t;
  2231.                                                     strike[7].ptype=pass_type;
  2232.                                                     strike[7].pplr=receiver;
  2233.                                                     strike[7].atime=ft_jtm;
  2234.                                                       strike[7].gt=gt;
  2235.                                                     strike[7].x=x-cx;
  2236.                                                     strike[7].y=y-cy;
  2237.                                                     strike[7].stop=stop_and_face;
  2238.                                                     do_it=TRUE;
  2239.                                                 }
  2240.                                             }
  2241.                                         }
  2242.                                     }
  2243.                                 }
  2244.                             }
  2245.                          }
  2246.                     }
  2247.                 }
  2248.             }
  2249.         }
  2250.     }
  2251.     return(do_it);
  2252. }
  2253. #else
  2254.  
  2255. // No first-time passing...
  2256.  
  2257. char can_i_intercept(int p_num,float x,float y,float z,float px,float py,short i)
  2258. {
  2259.     if (z>=teams[p_num-1].tm_jump)
  2260.         return(FALSE);
  2261.  
  2262.     float cx,cy,cz,cx2,cy2,ang;
  2263.     float rate=full_spd(&teams[p_num-1]);
  2264.     float d=calc_dist(x-px,y-py);
  2265.     char can_strike;
  2266.     char do_it=FALSE;
  2267.     char stand;
  2268.  
  2269.     short ff=1+teams[p_num-1].tm_flair/16;        // Reaction times.
  2270.  
  2271.     short gt=get_there_time(p_num,x,y);
  2272.     short t;
  2273.  
  2274.     if (gt<=i)
  2275.     {
  2276. // He can get to ball in time...
  2277.  
  2278.         if (ball_poss)
  2279.         {
  2280. // Opponent has ball... (No control or strike!)
  2281. /***** RUN ONTO BALL *****/
  2282.             t=i-gt;
  2283.             if (t>0 && t<strike[0].free && (teams[p_num-1].control || t<ff))
  2284.             {
  2285.                   strike[0].t=i;
  2286.                   strike[0].free=t;
  2287.                 strike[0].x=x;
  2288.                 strike[0].y=y;
  2289.                 strike[0].stop=stop_and_face;
  2290.                 do_it=TRUE;
  2291.             }
  2292.         }
  2293.         else
  2294.         {
  2295.             if (user_controlled)
  2296.             {
  2297.                 can_strike=128+32+16+8+4+2+1;
  2298.                 pass_type=0;
  2299.             }
  2300.             else
  2301.                 can_strike=first_time_strike(p_num,x,y,z,px,py);
  2302.  
  2303. /***** RUN ONTO BALL *****/
  2304.  
  2305.             if (z<PLAYER_HEIGHT/3)
  2306.             {
  2307. // Feet level...
  2308.                 ang=angle_to_xy(x-px,y-py,teams[p_num-1].tm_xdis,teams[p_num-1].tm_ydis);
  2309.                 if (ang>0 || user_controlled)
  2310.                 {
  2311. // Target is in front of player...
  2312.                     t=i-gt;
  2313.                     if (t>=0 && t<strike[0].free && (teams[p_num-1].control || t<ff))
  2314.                     {
  2315.                           strike[0].t=i;
  2316.                           strike[0].free=t;
  2317.                         strike[0].x=x;
  2318.                         strike[0].y=y;
  2319.                         strike[0].stop=stop_and_face;
  2320.                         do_it=TRUE;
  2321.                     }
  2322.                 }
  2323.             }
  2324.  
  2325. //            if (plr_facing(x-px,y-py,&teams[p_num-1]) && target_towards_ball(x,y,px,py)
  2326. //            if ((target_towards_ball(x,y,px,py) || stop_and_face) &&
  2327. //            if (
  2328. //                 teams[p_num-1].tm_act<=TURN_ACT)
  2329.             
  2330.             if ((p_num!=KP_A && p_num!=KP_B)
  2331.                  || (p_num==KP_A && cannot_pick_up<12) || (p_num==KP_B && cannot_pick_up>11))
  2332.             {
  2333. // Keeper cannot pick ball up...
  2334.  
  2335. // Player must be running or standing...
  2336.  
  2337.                 if (teams[p_num-1].tm_trap>=0)
  2338.                 {
  2339. // Must control ball or may hit it first time...
  2340.  
  2341. /***** TRAP AND CONTROL *****/
  2342.  
  2343.                     if (can_strike&128)
  2344.                     {
  2345.                         if (z<PLAYER_HEIGHT/2)
  2346.                         {
  2347. // Feet level...
  2348.                             rotate_offs(MC_TRAPL,cx,cy,cz,x_face,y_face);
  2349.                             rotate_offs(MC_TRAPR,cx2,cy2,cz,x_face,y_face);
  2350.                             cx=(cx+cx2)/2;
  2351.                             cy=(cy+cy2)/2;
  2352.                             gt=get_there_time(p_num,x-cx,y-cy);
  2353.                             t=i-(gt+ft_ttm);
  2354.                             if (t>=0 && t<strike[1].free && (teams[p_num-1].control || t<ff))
  2355.                             {
  2356. // He has time to animate...
  2357. // Best so far!
  2358.                                 special_move=TRUE;
  2359.                                 if ((user_controlled && uf2) || !user_controlled)
  2360.                                 {
  2361.                                       strike[1].t=i;
  2362.                                       strike[1].free=t;
  2363.                                     strike[1].atime=ft_ttm;
  2364.                                       strike[1].gt=gt;
  2365.                                     strike[1].x=x-cx;
  2366.                                     strike[1].y=y-cy;
  2367.                                     strike[1].stop=stop_and_face;
  2368.                                     do_it=TRUE;
  2369.                                 }
  2370.                             }
  2371.                         }
  2372.                         else
  2373.                         {
  2374.                             if (z<(PLAYER_HEIGHT-2))
  2375.                             {
  2376. // Chest level...
  2377.                                 rotate_offs(MC_CHEST,cx,cy,cz,x_face,y_face);
  2378.                                 gt=get_there_time(p_num,x-cx,y-cy);
  2379.                                 t=i-(gt+ft_ctm);
  2380.                                 if (t>=0 && t<strike[2].free && (teams[p_num-1].control || t<ff))
  2381.                                 {
  2382. // He has time to animate...
  2383. // Best so far!
  2384.                                     special_move=TRUE;
  2385.                                     if ((user_controlled && uf2) || !user_controlled)
  2386.                                     {
  2387.                                           strike[2].t=i;
  2388.                                           strike[2].free=t;
  2389.                                         strike[2].atime=ft_ctm;
  2390.                                           strike[2].gt=gt;
  2391.                                         strike[2].x=x-cx;
  2392.                                         strike[2].y=y-cy;
  2393.                                         strike[2].stop=stop_and_face;
  2394.                                         do_it=TRUE;
  2395.                                     }
  2396.                                 }
  2397.                             }
  2398.                             else
  2399.                             {
  2400.                                 if (z<(PLAYER_HEIGHT+4))
  2401.                                 {
  2402. // Head level...
  2403.                                     rotate_offs(MC_D_HEAD,cx,cy,cz,x_face,y_face);
  2404.                                     gt=get_there_time(p_num,x-cx,y-cy);
  2405.                                     t=i-(gt+ft_utm);
  2406.                                     if (t>=0 && t<strike[3].free && (teams[p_num-1].control || t<ff))
  2407.                                     {
  2408. // He has time to animate...
  2409. // Best so far!
  2410.                                         special_move=TRUE;
  2411.                                         if ((user_controlled && uf2) || !user_controlled)
  2412.                                         {
  2413.                                               strike[3].t=i;
  2414.                                               strike[3].free=t;
  2415.                                             strike[3].atime=ft_utm;
  2416.                                               strike[3].gt=gt;
  2417.                                             strike[3].x=x-cx;
  2418.                                             strike[3].y=y-cy;
  2419.                                             strike[3].stop=stop_and_face;
  2420.                                             do_it=TRUE;
  2421.                                         }
  2422.                                     }
  2423.                                 }
  2424.                             }
  2425.                         }
  2426.                     }
  2427.                 }
  2428.  
  2429.                 if (teams[p_num-1].tm_trap<=0)
  2430.                 {
  2431.     
  2432. // May hit it first time...
  2433.  
  2434. /***** FIRST TIME STRIKE *****/
  2435.  
  2436.                     if (z<PLAYER_HEIGHT/4)
  2437.                     {
  2438.                         if (can_strike&1)
  2439.                         {
  2440. // Feet level...
  2441.                             rotate_offs(MC_SHOOTL,cx,cy,cz,x_face,y_face);
  2442.                             rotate_offs(MC_SHOOTR,cx2,cy2,cz,x_face,y_face);
  2443.                             cx=(cx+cx2)/2;
  2444.                             cy=(cy+cy2)/2;
  2445.                             gt=get_there_time(p_num,x-cx,y-cy);
  2446.                             t=i-(gt+ft_ktm);
  2447.                             if (t>=0 && t<strike[8].free && (teams[p_num-1].control || t<ff))
  2448.                             {
  2449. // He has time to animate...
  2450. // Best so far!
  2451.                                 special_move=TRUE;
  2452.                                 if ((user_controlled && uf1) || !user_controlled)
  2453.                                 {
  2454.                                       strike[8].t=i;
  2455.                                       strike[8].free=t;
  2456.                                     strike[8].atime=ft_ktm;
  2457.                                       strike[8].gt=gt;
  2458.                                     strike[8].x=x-cx;
  2459.                                     strike[8].y=y-cy;
  2460.                                     strike[8].stop=stop_and_face;
  2461.                                     do_it=TRUE;
  2462.                                 }
  2463.                             }
  2464.                         }
  2465.  
  2466.                         if (can_strike&64)
  2467.                         {
  2468. // Feet level...
  2469.                             rotate_offs(MC_CHIPL,cx,cy,cz,x_face,y_face);
  2470.                             rotate_offs(MC_CHIPR,cx2,cy2,cz,x_face,y_face);
  2471.                             cx=(cx+cx2)/2;
  2472.                             cy=(cy+cy2)/2;
  2473.                             gt=get_there_time(p_num,x-cx,y-cy);
  2474.                             t=i-(gt+ft_ctm);
  2475.                             if (t>=0 && t<strike[10].free && (teams[p_num-1].control || t<ff))
  2476.                             {
  2477. // He has time to animate...
  2478. // Best so far!
  2479.                                 special_move=TRUE;
  2480.                                 if ((user_controlled && uf1) || !user_controlled)
  2481.                                 {
  2482.                                       strike[10].t=i;
  2483.                                       strike[10].free=t;
  2484.                                     strike[10].ptype=pass_type;
  2485.                                     strike[10].pplr=receiver;
  2486.                                     strike[10].atime=ft_ctm;
  2487.                                       strike[10].gt=gt;
  2488.                                     strike[10].x=x-cx;
  2489.                                     strike[10].y=y-cy;
  2490.                                     strike[10].stop=stop_and_face;
  2491.                                     do_it=TRUE;
  2492.                                 }
  2493.                             }
  2494.                         }
  2495.                     }
  2496.                     else
  2497.                     {
  2498.                         if (z<PLAYER_HEIGHT*.5)
  2499.                         {
  2500. // volley level...
  2501.                             if (can_strike&2)
  2502.                             {
  2503.                                 rotate_offs(MC_VOLLEYL,cx,cy,cz,x_face,y_face);
  2504.                                 gt=get_there_time(p_num,x-cx,y-cy);
  2505.                                 t=i-(gt+ft_vtm);
  2506.                                 if (t>=0 && t<strike[5].free && (teams[p_num-1].control || t<ff))
  2507.                                 {
  2508. // He has time to animate...
  2509. // Best so far!
  2510.                                     special_move=TRUE;
  2511.                                     if ((user_controlled && uf1) || !user_controlled)
  2512.                                     {
  2513.                                           strike[5].t=i;
  2514.                                           strike[5].free=t;
  2515.                                         strike[5].atime=ft_vtm;
  2516.                                           strike[5].gt=gt;
  2517.                                         strike[5].x=x-cx;
  2518.                                         strike[5].y=y-cy;
  2519.                                         strike[5].stop=stop_and_face;
  2520.                                         do_it=TRUE;
  2521.                                     }
  2522.                                 }
  2523.                             }
  2524.                         }
  2525.                         else
  2526.                         {
  2527.                             if (z<PLAYER_HEIGHT*.67)
  2528.                             {
  2529.                                 if (can_strike&4)
  2530.                                 {
  2531.                                     rotate_offs(MC_DV_HEAD,cx,cy,cz,x_face,y_face);
  2532.                                     gt=get_there_time(p_num,x-cx,y-cy);
  2533.                                     t=i-(gt+ft_dtm);
  2534.                                     if (t>=0 && t<strike[6].free && (teams[p_num-1].control || t<ff))
  2535.                                     {
  2536. // He has time to animate...
  2537. // Best so far!
  2538.                                         special_move=TRUE;
  2539.                                         if ((user_controlled && uf1) || !user_controlled)
  2540.                                         {
  2541.                                               strike[6].t=i;
  2542.                                               strike[6].free=t;
  2543.                                             strike[6].atime=ft_dtm;
  2544.                                               strike[6].gt=gt;
  2545.                                             strike[6].x=x-cx;
  2546.                                             strike[6].y=y-cy;
  2547.                                             strike[6].stop=stop_and_face;
  2548.                                             do_it=TRUE;
  2549.                                         }
  2550.                                     }
  2551.                                 }
  2552.                             }
  2553.                             else
  2554.                             {
  2555.                                 if (z<PLAYER_HEIGHT+2)
  2556.                                 {
  2557. // head level...
  2558.                                     if (can_strike&32)
  2559.                                     {
  2560.                                         rotate_offs(MC_OVERHEAD,cx,cy,cz,x_face,y_face);
  2561.                                         gt=get_there_time(p_num,x-cx,y-cy);
  2562.                                         t=i-(gt+ft_otm);
  2563.                                         if (t>=0 && t<strike[4].free && (teams[p_num-1].control || t<ff))
  2564.                                         {
  2565. // He has time to animate...
  2566. // Best so far!
  2567.                                             special_move=TRUE;
  2568.                                             if ((user_controlled && uf1) || !user_controlled)
  2569.                                             {
  2570.                                                   strike[4].t=i;
  2571.                                                   strike[4].free=t;
  2572.                                                 strike[4].atime=ft_otm;
  2573.                                                   strike[4].gt=gt;
  2574.                                                 strike[4].x=x-cx;
  2575.                                                 strike[4].y=y-cy;
  2576.                                                 strike[4].stop=stop_and_face;
  2577.                                                 do_it=TRUE;
  2578.                                             }
  2579.                                         }
  2580.                                     }
  2581.  
  2582.                                     if (can_strike&8)
  2583.                                     {
  2584. // He has time...
  2585.                                         rotate_offs(MC_S_HEAD,cx,cy,cz,x_face,y_face);
  2586.                                         gt=get_there_time(p_num,x-cx,y-cy);
  2587.                                         t=i-(gt+ft_stm);
  2588.                                         if (t>=0 && t<strike[9].free && (teams[p_num-1].control || t<ff))
  2589.                                         {
  2590. // He has time to animate...
  2591. // Best so far!
  2592.                                             special_move=TRUE;
  2593.                                             if ((user_controlled && uf1) || !user_controlled)
  2594.                                             {
  2595.                                                   strike[9].t=i;
  2596.                                                   strike[9].free=t;
  2597.                                                 strike[9].ptype=pass_type;
  2598.                                                 strike[9].pplr=receiver;
  2599.                                                 strike[9].atime=ft_stm;
  2600.                                                   strike[9].gt=gt;
  2601.                                                 strike[9].x=x-cx;
  2602.                                                 strike[9].y=y-cy;
  2603.                                                 strike[9].stop=stop_and_face;
  2604.                                                 do_it=TRUE;
  2605.                                             }
  2606.                                         }
  2607.                                     }
  2608.                                 }
  2609.                                 else
  2610.                                 {
  2611.                                     if (z<teams[p_num-1].tm_jump)
  2612.                                     {
  2613. // Jump level...
  2614.                                         if (can_strike&16)
  2615.                                         {
  2616. // He has time...
  2617.                                             rotate_offs(MC_J_HEAD,cx,cy,cz,x_face,y_face);
  2618.                                             gt=get_there_time(p_num,x-cx,y-cy);
  2619.                                             t=i-(gt+ft_jtm);
  2620.                                             if (ABS(cz+prat-z)<8 && t>=0 && t<strike[7].free && (teams[p_num-1].control || t<ff))
  2621.                                             {
  2622. // He has time to animate...
  2623. // Best so far!
  2624.                                                 special_move=TRUE;
  2625.                                                 if ((user_controlled && uf1) || !user_controlled)
  2626.                                                 {
  2627.                                                       strike[7].t=i;
  2628.                                                       strike[7].free=t;
  2629.                                                     strike[7].ptype=pass_type;
  2630.                                                     strike[7].pplr=receiver;
  2631.                                                     strike[7].atime=ft_jtm;
  2632.                                                       strike[7].gt=gt;
  2633.                                                     strike[7].x=x-cx;
  2634.                                                     strike[7].y=y-cy;
  2635.                                                     strike[7].stop=stop_and_face;
  2636.                                                     do_it=TRUE;
  2637.                                                 }
  2638.                                             }
  2639.                                         }
  2640.                                     }
  2641.                                 }
  2642.                             }
  2643.                          }
  2644.                     }
  2645.                 }
  2646.             }
  2647.         }
  2648.     }
  2649.     return(do_it);
  2650. }
  2651. #endif
  2652.  
  2653. /*******************************************************************************
  2654. *****************************************************************************/
  2655.  
  2656. void clear_strike()
  2657.  
  2658. {
  2659. // Clear first time animation array...
  2660.     for (short i=0; i<11; i++)
  2661.     {
  2662.         strike[i].t=0;            // Init start time.
  2663.         strike[i].free=1000;    // Init wait time.
  2664.         strike[i].ptype=0;
  2665.         strike[i].pplr=0;
  2666.     }
  2667. }
  2668.  
  2669. /*******************************************************************************
  2670. *****************************************************************************/
  2671.  
  2672. void decide_on_face(match_player *p)
  2673. {
  2674.     float gx,gy,x,y,d;
  2675.     if (p->tm_player<12)
  2676. // Team A...
  2677.         gx=0;        // His goal...
  2678.     else
  2679.         gx=pitch_len;        // His goal...
  2680.  
  2681.     gy=cntspot_y;
  2682.  
  2683.     gx=gx-p->tm_x;
  2684.     gy=gy-p->tm_y;
  2685.  
  2686.     d=calc_dist(gx,gy);
  2687.     if (d<prat*30)
  2688.     {
  2689. // In Defense...
  2690.  
  2691.         if (p->tm_player<12)
  2692.             must_face_x=1;
  2693.         else
  2694.             must_face_x=-1;
  2695.  
  2696.         must_face=TRUE;
  2697.     }
  2698.     else
  2699.     {
  2700. // Not in defense...
  2701.         if (p->tm_player<12)
  2702.             gx=pitch_len;
  2703.         else
  2704.             gx=0;
  2705.         
  2706.         gx=gx-p->tm_x;
  2707.  
  2708.         d=calc_dist(gx,gy);
  2709.         if (d<(MIN_SHOOT_DIST+((float)p->tm_pow*3)))
  2710.         {
  2711. // In Shooting Range...            
  2712.             must_face_x=gx/d;
  2713.             must_face_y=gy/d;
  2714.             must_face=TRUE;
  2715.  
  2716.         }
  2717.     }
  2718. }
  2719.  
  2720. /*******************************************************************************
  2721. *****************************************************************************/
  2722.  
  2723. char go_to_path(int p_num)
  2724. // Send player(p_num) to intersection with ball path.
  2725. // If he cannot meet ball then best try!
  2726.  
  2727. {
  2728.     float spd_up;
  2729.     special_move=FALSE;
  2730.  
  2731.     teams[p_num-1].tm_fpass_type=0;
  2732.     teams[p_num-1].tm_fpass_to=0;
  2733.  
  2734.     float x,y,z;
  2735.     float px=teams[p_num-1].tm_x;
  2736.     float py=teams[p_num-1].tm_y;
  2737.     short i;
  2738.     char do_it=FALSE;
  2739.  
  2740.     first_time_it=TRUE;
  2741.  
  2742.     clear_strike();
  2743.  
  2744. /*** Capture Timings ***/
  2745. /* Release Ball */
  2746.  
  2747.     if (user_controlled)
  2748. // Allow user to animate faster for responsiveness...
  2749.         spd_up=1.3;
  2750.     else
  2751.         spd_up=1;
  2752.  
  2753. // Kick time...
  2754.     ft_ktm=MCC_SHOOT/(MC_SHOOT_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2755.  
  2756. // Volley time...
  2757.     ft_vtm=MCC_VOLLEY/(MC_VOLLEY_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2758.  
  2759. // Diving time...
  2760.     ft_dtm=MCC_DV_HEAD/(MC_DV_HEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2761.  
  2762. // Overhead time...
  2763.     ft_otm=MCC_OVERHEAD/(MC_OVERHEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2764.  
  2765. // Standing time...
  2766.     ft_stm=MCC_S_HEAD/(MC_S_HEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2767.  
  2768. // Jumping time...
  2769.     ft_jtm=MCC_J_HEAD/(MC_J_HEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2770. //        ft_jtm=MCC_J_HEAD/MC_J_HEAD_FS;
  2771.  
  2772. /* Keep Ball */
  2773.  
  2774. // Trapping time...
  2775.     ft_ttm=MCC_TRAP/(MC_TRAP_FS*spd_up*fstep_factor(teams[p_num-1].tm_cont));
  2776.  
  2777. // Chesting time...
  2778.     ft_ctm=MCC_CHEST/(MC_CHEST_FS*spd_up*fstep_factor(teams[p_num-1].tm_cont));
  2779.  
  2780. // Up head time...
  2781.     ft_utm=MCC_D_HEAD/(MC_D_HEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_cont));
  2782.  
  2783.     must_face=FALSE;
  2784.  
  2785.     auto_select=FALSE;
  2786.  
  2787.     if (user_controlled)
  2788.     {
  2789.         if (um && (uf1 || uf2))
  2790. // User.. Directional control...
  2791.         {
  2792.             must_face=TRUE;        // Forced to face in a particular dir...
  2793.             must_face_x=ux;
  2794.             must_face_y=uy;
  2795.         }
  2796.         else
  2797.             if (uf1 || uf2)
  2798.             {
  2799. // User.. No directional control...
  2800.                 decide_on_face(&teams[p_num-1]);
  2801.             }
  2802.     }
  2803.     else
  2804.     {
  2805.         if ((p_num<12 && !auto_users_a) || p_num==KP_A
  2806.              || (p_num>11 && !auto_users_b) || p_num==KP_B)
  2807.         {
  2808. // Computer player will try to face goal or away from defense...
  2809.             auto_select=TRUE;
  2810.  
  2811.             if (p_num==receiver_a || p_num==receiver_b)
  2812.             {
  2813.                 decide_on_face(&teams[p_num-1]);
  2814.             }
  2815.         }
  2816.         else
  2817.         {
  2818. // Should be a user...
  2819.             auto_select=FALSE;        // Don't allow computer to select a move!
  2820.         }
  2821.     }
  2822.  
  2823.     for (i=1; i<50; i+=2)
  2824.     {
  2825.         x=ball_pred_tab[i][0];
  2826.         y=ball_pred_tab[i][1];
  2827.         z=ball_pred_tab[i][2];
  2828.  
  2829.         ball_int_speed=ABS(x-ball_pred_tab[i-1][0])
  2830.                           +ABS(y-ball_pred_tab[i-1][1])
  2831.                           +(ABS(z-ball_pred_tab[i-1][2])*2);
  2832.  
  2833.         if ((x<0) || (x>=pitch_len) || (y<0) || (y>=pitch_wid))
  2834. // Ball out of bounds
  2835.         {
  2836.             x=ball_pred_tab[i-1][0];
  2837.             y=ball_pred_tab[i-1][1];
  2838.             i=60;
  2839.         }
  2840.         else
  2841.         {
  2842.             do_it+=can_i_intercept(p_num,x,y,z,px,py,i);
  2843.         }
  2844.     }
  2845.  
  2846.     if (do_it)
  2847.     {
  2848. /*
  2849.         if ((p_num<12 && auto_users_a && !teams[p_num-1].control)
  2850.             || (p_num>11 && auto_users_b && !teams[p_num-1].control))
  2851.         {
  2852.             reselect();
  2853.             user_conts(&teams[p_num-1]);
  2854.             user_controlled=teams[p_num-1].control;
  2855.         }
  2856. */
  2857.         intercept(p_num);
  2858.  
  2859.         if (ball_poss)
  2860.             teams[p_num-1].ball_state=-ball_poss;
  2861.         else
  2862.             teams[p_num-1].ball_state=last_touch;
  2863.     }
  2864.  
  2865.     must_face=FALSE;
  2866.     first_time_it=FALSE;
  2867.     return(do_it);
  2868. }
  2869.  
  2870. /******************************************************************************
  2871. *****************************************************************************/
  2872.  
  2873. void ogo_to_path(int p_num,char header_only)
  2874.  
  2875. // Send player(p_num) to intersection with ball path.
  2876. // If he cannot meet ball then best try!
  2877.  
  2878. {
  2879.     float x,y,z,d;
  2880.     float px=teams[p_num-1].tm_x;
  2881.     float py=teams[p_num-1].tm_y;
  2882.     float rate=actual_spd(&teams[p_num-1]);
  2883.     action="Intercept";
  2884.  
  2885.     reset_ideas(&teams[p_num-1]);
  2886.  
  2887.     if (p_num<12)
  2888.         interceptor_a=p_num;
  2889.     else
  2890.         interceptor_b=p_num;
  2891.  
  2892. // His intention is to intercept ball.
  2893. // Therefore his flair determines no. of turns before rethink!
  2894.  
  2895.     int ff=33-(teams[p_num-1].tm_flair/4);
  2896.     teams[p_num-1].int_move=I_INTERCEPT;        // Intercept ball!
  2897.     teams[p_num-1].int_cnt=ff;                        // Flair factor.
  2898.  
  2899.     char feet_hit=FALSE;
  2900.     char body_hit=FALSE;
  2901.     char head_hit=FALSE;
  2902.  
  2903.     float feet_x,feet_y,body_x,body_y,head_x,head_y;
  2904.  
  2905.     for (int i=1; i<50; i++)
  2906.     {
  2907.         x=ball_pred_tab[i][0];
  2908.         y=ball_pred_tab[i][1];
  2909.         z=ball_pred_tab[i][2];
  2910.  
  2911.         if ((x<0) || (x>=pitch_len) || (y<0) || (y>=pitch_wid))
  2912. // Ball out of bounds
  2913.         {
  2914.             x=ball_pred_tab[i-1][0];
  2915.             y=ball_pred_tab[i-1][1];
  2916.             i=60;
  2917.         }
  2918.         else
  2919.         {
  2920.             if (z<PLAYER_HEIGHT/2)
  2921.             {
  2922.                   d=calc_dist(x-px,y-py);
  2923.                 d=(int)(((float)d)/rate);                    //How many steps?
  2924.  
  2925.                 if (d<=i)
  2926. // He can get there in time!
  2927. // At feet...
  2928.                 {
  2929.                     feet_x=x;
  2930.                     feet_y=y;
  2931.                     feet_hit=TRUE;
  2932.                     i=60;
  2933.                 }
  2934.             }
  2935.             else
  2936.             {
  2937.                 if ((z<=PLAYER_HEIGHT-4) && (!body_hit))
  2938.                 {
  2939.                       d=calc_dist(x-px,y-py);
  2940.                     d=(int)(((float)d)/rate);                    //How many steps?
  2941.  
  2942.                     if (d<=i)
  2943. // He can get there in time!
  2944. // On body...
  2945.                     {
  2946.                         body_x=x;
  2947.                         body_y=y;
  2948.                         body_hit=TRUE;
  2949.                     }
  2950.  
  2951. //                    init_run_act(&teams[p_num-1],x,y,TRUE);                //Go to path point!
  2952. //                    i=60;                                                // End For Loop!
  2953.                 }
  2954.                 else
  2955.                 {
  2956.                       if ((z>PLAYER_HEIGHT-4) && (z<=teams[p_num-1].tm_jump) && (!head_hit))
  2957.                     {
  2958.                         d=calc_dist(x-px,y-py);
  2959.                         d=(int)(((float)d)/rate);                    //How many steps?
  2960.  
  2961.                         if (d+(sqrt(z-PLAYER_HEIGHT+5)/gravity)<=i)
  2962. // He can get there in time!
  2963. // On head...
  2964.                         {
  2965.                             head_x=x;
  2966.                             head_y=y;
  2967.                             head_hit=TRUE;
  2968.                         }
  2969.  
  2970. //                        init_run_act(&teams[p_num-1],x,y,TRUE);                //Go to path point!
  2971. //                        i=60;
  2972.                     }
  2973.                 }
  2974.             }
  2975.         }
  2976.     }
  2977.     
  2978.     if ((!feet_hit) && (!head_hit) && (!body_hit))
  2979. // He cant intersect!
  2980.     {
  2981.         init_run_act(&teams[p_num-1],x,y,TRUE);            // run toward last.
  2982.     }
  2983.     else
  2984.     {
  2985.         if (header_only)
  2986.         {
  2987.             if (head_hit)
  2988.             {
  2989.                 init_run_act(&teams[p_num-1],head_x,head_y,TRUE);    //Go to path point!
  2990.             }
  2991.         }
  2992.         else
  2993.         {
  2994.             if (feet_hit)
  2995.             {
  2996.                 init_run_act(&teams[p_num-1],feet_x,feet_y,TRUE);    //pitch line point
  2997.             }
  2998.             else
  2999.                 if (head_hit)
  3000.                 {
  3001.                     init_run_act(&teams[p_num-1],head_x,head_y,TRUE);    //Go to path point!
  3002.                 }
  3003.                 else
  3004.                     if (body_hit)
  3005.                     {
  3006.                         init_run_act(&teams[p_num-1],body_x,body_y,TRUE);    //Go to path point!
  3007.                     }
  3008.         }
  3009.     }
  3010. }
  3011.  
  3012. /******************************************************************************
  3013. *****************************************************************************/
  3014.  
  3015. void get_tack_path(match_player *player)
  3016.  
  3017. // Find players intersection with ball path.
  3018. // When tackling!
  3019.  
  3020. {
  3021.     if (teams[ball_poss-1].tm_poss>4)
  3022.     {
  3023. // Opponent has ball for a bit...
  3024.  
  3025.         flag=FALSE;
  3026.         float x,y,z;
  3027.         float d,s;
  3028.         float px=player->tm_x;
  3029.         float py=player->tm_y;
  3030.         float rate=player->tm_rate+player->tm_pow;
  3031.         float last_diff=2000;
  3032.  
  3033.         if (((ball_poss) && (teams[ball_poss-1].tm_act==STAND_ACT))
  3034.             || ((!ball_poss) && (ball_still)))
  3035.  
  3036. // Ball is not moving!
  3037.             if (plr_facing(ballx,bally,player))
  3038.                 init_tackle_act(player,ballx,bally);                //Go to path point!
  3039.             else
  3040.                 go_to_path(player->tm_player);
  3041.         else
  3042.         {
  3043.  
  3044.             for (int i=1; i<TACKLE_TURNS/2; i++)
  3045.             {
  3046.                 x=ball_pred_tab[i][0];
  3047.                 y=ball_pred_tab[i][1];
  3048.                 z=ball_pred_tab[i][2];
  3049.  
  3050.                 if ((x<0) || (x>=pitch_len) || (y<0) || (y>=pitch_wid))
  3051. // Ball out of bounds (So don't tackle!)
  3052.                     i=60;
  3053.  
  3054.                 if (z<=PLAYER_HEIGHT/2)
  3055. // Tackling player is half height.
  3056.                 {
  3057.                     d=calc_dist(x-px,y-py);
  3058.  
  3059. // Now the tricky bit...
  3060. // Using S=a(1-r^n)/(1-r) (S=tackle distance over time (n))
  3061. // a=(rate/8), r=tackle_decel...
  3062.  
  3063.                     s=(rate/20)*(1-pow(TACKLE_DECEL,i))/(1-TACKLE_DECEL);    //How far in time (i)!
  3064.  
  3065.                     if (d-s>last_diff)
  3066. // Ball getting further away!
  3067.                         i=60;                                                // End For Loop!
  3068.                     else
  3069.                         last_diff=d-s;
  3070.  
  3071.                     if (last_diff<=0)
  3072. // He can get there in time!
  3073.                     {
  3074.  
  3075. // Take accuracy into account...
  3076.  
  3077.                         float acc_xoff=(seed*(128-player->tm_ac)/4)/128;
  3078.                         af_randomize();
  3079.                         float acc_yoff=(seed*(128-player->tm_ac)/4)/128;
  3080.                         if (seed&32) 
  3081.                             acc_xoff=-acc_xoff;
  3082.                         if (seed&16)
  3083.                             acc_yoff=-acc_yoff;
  3084.                         if (player->tm_player!=KP_A && player->tm_player!=KP_B)
  3085. //                            init_tackle_act(player,x+acc_xoff,y+acc_yoff);                //Go to path point!
  3086.                             init_tackle_act(player,x,y);
  3087.                         else
  3088. // Keeper more accurate to provide better defense...
  3089.                             init_tackle_act(player,x,y);
  3090.                         flag=TRUE;
  3091.                         i=60;                                                // End For Loop!
  3092.                     }
  3093.                 }
  3094.             }
  3095.         }
  3096.     }
  3097. }
  3098.  
  3099. /******************************************************************************
  3100. *****************************************************************************/
  3101.  
  3102. void set_there_flags(short taker)
  3103. {
  3104. #ifdef EURO96
  3105.      if ((teams[taker-1].tm_act==STAND_ACT && plr_facing(ballx-teams[taker-1].tm_x,bally-teams[taker-1].tm_y,&teams[taker-1]))
  3106.          && (teams[taker-1].tm_dist<BESIDE_BALL*3
  3107.          || ((match_mode==PEN_KICK_A || match_mode==PEN_KICK_B) && teams[taker-1].tm_dist<(PEN_RUNUP_DIST+4))))
  3108. #else
  3109.      if ((teams[taker-1].tm_act==STAND_ACT && plr_facing(ballx-teams[taker-1].tm_x,bally-teams[taker-1].tm_y,&teams[taker-1]))
  3110.          && (teams[taker-1].tm_dist<BESIDE_BALL*3))
  3111. #endif
  3112.      {
  3113.           if (!already_there)
  3114.         {
  3115.             reselection=TRUE;
  3116.                already_there=TRUE;
  3117.         }
  3118.     }
  3119. }
  3120.  
  3121. /******************************************************************************
  3122. *****************************************************************************/
  3123.  
  3124. void centre_pos(char flag,int pn,char &flag2,float &x,float &y)
  3125. {
  3126. // Taking centre!
  3127.     {
  3128.         if (((pn+1==centre_guy_1) && (flag==1))
  3129.             || ((pn+1==centre_guy_1-11) && (flag==2)))
  3130.         {
  3131.             x=cntspot_x;
  3132.             y=cntspot_y-10;
  3133.             flag2=TRUE;
  3134.             set_there_flags(centre_guy_1);
  3135.         }
  3136.  
  3137.         if (((pn+1==centre_guy_2) && (flag==1))
  3138.             || ((pn+1==centre_guy_2-11) && (flag==2)))
  3139.         {
  3140.             if (flag==1)
  3141.                 x=cntspot_x+5;
  3142.             else
  3143.                 x=cntspot_x-5;            // Receiver stands over line...
  3144.  
  3145.             y=cntspot_y+10;
  3146.             flag2=TRUE;
  3147.         }
  3148.     }
  3149. }
  3150.  
  3151. /******************************************************************************
  3152. *****************************************************************************/
  3153.  
  3154. void gkick_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  3155. {
  3156. // Taking Goal kick!
  3157.     {
  3158.         if (((pn+1==gkick_taker) && (flag==1))
  3159.             || ((pn+1==gkick_taker-11) && (flag==2)))
  3160.         {
  3161.             x=taker_x;
  3162.             y=taker_y;
  3163.  
  3164.             taker=TRUE;
  3165.  
  3166.             flag2=TRUE;
  3167.             if (flag==2)
  3168.             {
  3169.                 x=pitch_len-x;
  3170.                 y=pitch_wid-y;
  3171.             }
  3172.  
  3173.             set_there_flags(gkick_taker);
  3174.         }
  3175.     }
  3176. }
  3177.  
  3178. /******************************************************************************
  3179. *****************************************************************************/
  3180.  
  3181. void corner_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  3182. {
  3183. // Taking Corner!
  3184.     {
  3185.         if (((pn+1==corner_taker) && (flag==1))
  3186.             || ((pn+1==corner_taker-11) && (flag==2)))
  3187.         {
  3188.             x=incident_x;
  3189.             y=incident_y;
  3190.             taker=TRUE;
  3191.  
  3192.             flag2=TRUE;
  3193.             if (flag==2)
  3194.             {
  3195.                 x=pitch_len-x;
  3196.                 y=pitch_wid-y;
  3197.             }
  3198.             set_there_flags(corner_taker);
  3199.         }
  3200.     }
  3201. }
  3202.  
  3203. /******************************************************************************
  3204. *****************************************************************************/
  3205.  
  3206. void throw_in_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  3207. {
  3208. // Taking throw!
  3209.     {
  3210.         if (flag==2)
  3211.             pn=pn+11;
  3212.  
  3213.         if (pn+1==throw_in_taker)
  3214.         {
  3215.             x=incident_x;
  3216.             y=incident_y+((incident_y<cntspot_y) ? -8:8);
  3217.             taker=TRUE;
  3218.  
  3219.             flag2=TRUE;
  3220.             if (flag==2)
  3221.             {
  3222.                 x=pitch_len-x;
  3223.                 y=pitch_wid-y;
  3224.             }
  3225.             set_there_flags(throw_in_taker);
  3226.         }
  3227.     }
  3228. }
  3229.  
  3230. /******************************************************************************
  3231. *****************************************************************************/
  3232.  
  3233. void dfkick_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  3234. {
  3235. // Taking F.K.!
  3236.     {
  3237.         if (flag==2)
  3238.             pn=pn+11;
  3239.  
  3240.         if (pn+1==fkick_taker)
  3241.         {
  3242.             x=taker_x;
  3243.             y=taker_y;
  3244.             taker=TRUE;
  3245.             flag2=TRUE;
  3246.             if (flag==2)
  3247.             {
  3248.                 x=pitch_len-x;
  3249.                 y=pitch_wid-y;
  3250.             }
  3251.  
  3252.             set_there_flags(fkick_taker);
  3253.         }
  3254.         else
  3255.         {
  3256.             if (teams[pn].tm_wall)
  3257.             {
  3258.                 for (int i=0; i<men_in_wall; i++)
  3259.                 {
  3260.                     if (wguys[i].guy==pn+1)
  3261.                     {
  3262.                         x=wguys[i].x;
  3263.                         y=wguys[i].y;
  3264.                         flag2=TRUE;
  3265.                         i=men_in_wall;
  3266.                         if (flag==2)
  3267.                         {
  3268.                             x=pitch_len-x;
  3269.                             y=pitch_wid-y;
  3270.                         }
  3271.                     }
  3272.                 }
  3273.             }
  3274.         }
  3275.     }
  3276. }
  3277.  
  3278. /******************************************************************************
  3279. *****************************************************************************/
  3280.  
  3281. void fkick_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  3282. {
  3283. // Taking F.K.!
  3284.     {
  3285.         if (flag==2)
  3286.             pn=pn+11;
  3287.  
  3288.         if (pn+1==fkick_taker)
  3289.         {
  3290.             x=taker_x;
  3291.             y=taker_y;
  3292.             taker=TRUE;
  3293.             flag2=TRUE;
  3294.             if (flag==2)
  3295.             {
  3296.                 x=pitch_len-x;
  3297.                 y=pitch_wid-y;
  3298.             }
  3299.             set_there_flags(fkick_taker);
  3300.         }
  3301.     }
  3302. }
  3303.  
  3304. /******************************************************************************
  3305. *****************************************************************************/
  3306.  
  3307. void penalty_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  3308. {
  3309. // Taking F.K.!
  3310.     {
  3311.         if (flag==2)
  3312.             pn=pn+11;
  3313.  
  3314.         if (pn+1==penalty_taker)
  3315.         {
  3316.             x=taker_x;
  3317.             y=taker_y;
  3318.             taker=TRUE;
  3319.             flag2=TRUE;
  3320.             if (flag==2)
  3321.             {
  3322.                 x=pitch_len-x;
  3323.                 y=pitch_wid-y;
  3324.             }
  3325.  
  3326.             set_there_flags(penalty_taker);
  3327.         }
  3328.     }
  3329. }
  3330.  
  3331. /******************************************************************************
  3332. *****************************************************************************/
  3333.  
  3334. void tunnel_pos(char flag,int pn,float &x,float &y)
  3335. {
  3336.     float tx=stadlist[setup.stadium].tunlx;
  3337.     float ty=-stadlist[setup.stadium].tunlz;
  3338.     float tz=stadlist[setup.stadium].tunly;
  3339.     float d=GO_TO_POS_DIST;
  3340.  
  3341.     if (flag==2)
  3342.     {
  3343. // Team B...
  3344.         pn+=11;
  3345.         if (ABS(teams[pn].go_ty-ty)<prat || 
  3346.             (teams[pn].tm_x>=(tx+prat-d) && teams[pn].tm_x<=(tx+prat+d)))
  3347.         {
  3348. // In line with tunnel...
  3349.             x=pitch_len-(tx+prat);
  3350.             y=pitch_wid-(ty);
  3351.  
  3352.             if (ABS(teams[pn].tm_y-(pitch_wid-y))<prat*2)
  3353.             {
  3354. // At end of tunnel...(don't draw him!)
  3355.                 teams[pn].draw_me=FALSE;
  3356.             }
  3357.         }
  3358.         else
  3359.         {
  3360.             x=pitch_len-(tx+prat);
  3361.             if (ty>cntspot_y)
  3362. // Which goal-line...
  3363.                 y=0;
  3364.             else
  3365.                 y=pitch_wid;
  3366.         }
  3367.     }
  3368.     else
  3369.     {
  3370. // Team A...
  3371.         if (ABS(teams[pn].go_ty-ty)<prat ||
  3372.             (teams[pn].tm_x>=(tx-prat-d) && teams[pn].tm_x<=(tx-prat+d)))
  3373.         {
  3374. // In line with tunnel...
  3375.             x=tx-prat;
  3376.             y=ty;
  3377.  
  3378.             if (ABS(teams[pn].tm_y-y)<prat*2)
  3379.             {
  3380. // At end of tunnel...(don't draw him!)
  3381.                 teams[pn].draw_me=FALSE;
  3382.             }
  3383.         }
  3384.         else
  3385.         {
  3386.             x=tx-prat;
  3387.             if (ty>cntspot_y)
  3388. // Which goal-line...
  3389.                 y=pitch_wid;
  3390.             else
  3391.                 y=0;
  3392.         }
  3393.     }
  3394.     set_there_flags(pn+1);
  3395. }
  3396.         
  3397. /******************************************************************************
  3398. *****************************************************************************/
  3399.  
  3400. int get_tac(int *t)
  3401. {
  3402. //    (*t)++;
  3403. //    (*t)--;
  3404.     return(*t);
  3405. }
  3406.  
  3407. /******************************************************************************
  3408. *****************************************************************************/
  3409.  
  3410. void get_target(char flag,int bz,int zx,int zy,int pn,float &x,float &y,int tac[(32*2)+6][10][2])
  3411. {
  3412.     float ox,oy;
  3413.     char flag2=FALSE;
  3414.     char taker=FALSE;
  3415.  
  3416.     if (dead_ball_cnt)
  3417.     {
  3418.         if (match_mode==SWAP_ENDS)
  3419.  
  3420. // Into tunnel...
  3421.  
  3422.         {
  3423.             tunnel_pos(flag,pn,x,y);
  3424.             flag2=TRUE;
  3425.         }
  3426.  
  3427.         if (((match_mode==CENTRE_A) && (flag==1))
  3428.             || ((match_mode==CENTRE_B) && (flag==2)))
  3429.  
  3430. // Centre takers...
  3431.  
  3432.              centre_pos(flag,pn,flag2,x,y);
  3433.  
  3434.         if (((match_mode==GOAL_KICK_TL) || (match_mode==GOAL_KICK_BL) && (flag==1))
  3435.             || ((match_mode==GOAL_KICK_TR) || (match_mode==GOAL_KICK_BR) && (flag==2)))
  3436.  
  3437. // Goal kick takers...
  3438.  
  3439.             gkick_pos(flag,pn,flag2,x,y,taker);
  3440.  
  3441.         if (((match_mode==CORNER_TL) || (match_mode==CORNER_BL) && (flag==2))
  3442.             || ((match_mode==CORNER_TR) || (match_mode==CORNER_BR) && (flag==1)))
  3443.  
  3444. // Corner takers...
  3445.  
  3446.             corner_pos(flag,pn,flag2,x,y,taker);
  3447.  
  3448.         if ((match_mode==THROW_IN_A) || (match_mode==THROW_IN_B))
  3449.  
  3450. // Throw-in taker...
  3451.  
  3452.             throw_in_pos(flag,pn,flag2,x,y,taker);
  3453.  
  3454.         if ((match_mode==DF_KICK_A) || (match_mode==DF_KICK_B))
  3455.  
  3456. // Direct F.K....
  3457.  
  3458.             dfkick_pos(flag,pn,flag2,x,y,taker);
  3459.  
  3460.         if ((match_mode==IF_KICK_A) || (match_mode==IF_KICK_B))
  3461.  
  3462. // In-direct F.K....
  3463.  
  3464.             fkick_pos(flag,pn,flag2,x,y,taker);
  3465.  
  3466.         if ((match_mode==PEN_KICK_A) || (match_mode==PEN_KICK_B))
  3467.  
  3468. // Penalty Kick....
  3469.  
  3470.             penalty_pos(flag,pn,flag2,x,y,taker);
  3471.  
  3472.     }
  3473.  
  3474.     if (!flag2)
  3475. /**************************/
  3476. // Normal match play!
  3477.     {
  3478.         if ((man2man_b) && (flag==2) && (teams[pn+11].tm_mark))
  3479.         {
  3480. // Team B defends man-to-man...
  3481.             x=pitch_len-man2man[pn-1][0];
  3482.             y=pitch_wid-man2man[pn-1][1];
  3483.         }
  3484.         else
  3485.         {
  3486.             if ((man2man_a) && (flag==1) && (teams[pn].tm_mark))
  3487.             {
  3488. // Team A defends man-to-man...
  3489.                 x=man2man[pn-1][0];
  3490.                 y=man2man[pn-1][1];
  3491.             }
  3492.             else
  3493.             {
  3494. // Normal Zonal Position...
  3495.                  x=get_tac(&tac[bz][pn-1][0]);
  3496.                 y=get_tac(&tac[bz][pn-1][1]);
  3497.  
  3498.                 if (flag==1 && bz==68 && pn==centre_guy_2-1)
  3499.                 {
  3500.                     x=cntspot_x+80;
  3501.                     y=cntspot_y+10;
  3502.                     flag=0;
  3503.                 }
  3504.  
  3505.                 if (flag==2 && bz==69 && pn==centre_guy_2-12)
  3506.                 {
  3507.                     x=cntspot_x-80;
  3508.                     y=cntspot_y+10;
  3509.                     flag=0;
  3510.                 }
  3511.  
  3512.                 if (flag)
  3513.                 {
  3514.                     float bx=LIMIT(ballx,0,pitch_len);
  3515.                     float by=LIMIT(bally,0,pitch_wid);
  3516.  
  3517.                     if ((analogue) && (!ball_out_of_play) &&
  3518.                         ((!dead_ball_cnt) || (match_mode<CORNER_TL) || (match_mode>THROW_IN_B)))
  3519.                     {
  3520.                         if (flag==1)
  3521.                         {
  3522.                             ox=bx-zx;    // offset from centre of zone!
  3523.                             oy=by-zy;
  3524.                         }
  3525.                         else
  3526.                         {
  3527.                             ox=(pitch_len-bx)-zx;    // offset from centre of zone!
  3528.                             oy=(pitch_wid-by)-zy;
  3529.                         }
  3530.  
  3531.                         float xa,xb,xc,ya,yb,yc;
  3532.  
  3533.                         if (ox<=0)
  3534.                         {
  3535.                             int b=bz-1;
  3536.                             if (b<0)
  3537.                                 b=0;
  3538.  
  3539.                             xa=get_tac(&tac[b][pn-1][0]);                    //left zone
  3540.                             ya=get_tac(&tac[b][pn-1][1]);                    //left zone
  3541.  
  3542.                             if (oy<=0)
  3543.                             {
  3544.                                 b=bz-8-1;
  3545.                                 if (b<0)
  3546.                                     b=0;
  3547.                                 xb=get_tac(&tac[b][pn-1][0]);            //top left zone
  3548.                                 yb=get_tac(&tac[b][pn-1][1]);            //top left zone
  3549.                                 xc=get_tac(&tac[b+1][pn-1][0]);                //top zone
  3550.                                 yc=get_tac(&tac[b+1][pn-1][1]);                //top zone
  3551.                             }
  3552.                             else
  3553.                             {
  3554.                                 b=bz+8;
  3555.                                 if (b>31)
  3556.                                     b=31;
  3557.                                 xb=get_tac(&tac[b-1][pn-1][0]);            //bot left zone
  3558.                                 yb=get_tac(&tac[b-1][pn-1][1]);            //bot left zone
  3559.                                 xc=get_tac(&tac[b][pn-1][0]);                //bot zone
  3560.                                 yc=get_tac(&tac[b][pn-1][1]);                //bot zone
  3561.                             }
  3562.                         }    
  3563.                         else
  3564.                         {
  3565.                             int b=bz+1;
  3566.                             if (b>31)
  3567.                                 b=31;
  3568.                             xa=get_tac(&tac[b][pn-1][0]);                    //right zone
  3569.                             ya=get_tac(&tac[b][pn-1][1]);                    //right zone
  3570.  
  3571.                             if (oy<=0)
  3572.                             {
  3573.                                 b=bz-8;
  3574.                                 if (b<0)
  3575.                                     b=0;
  3576.                                 xb=get_tac(&tac[b+1][pn-1][0]);            //top right zone
  3577.                                 yb=get_tac(&tac[b+1][pn-1][1]);            //top right zone
  3578.                                 xc=get_tac(&tac[b][pn-1][0]);                //top zone
  3579.                                 yc=get_tac(&tac[b][pn-1][1]);                //top zone
  3580.                             }
  3581.                             else
  3582.                             {
  3583.                                 b=bz+8+1;
  3584.                                 if (b>31)
  3585.                                     b=31;
  3586.                                 xb=get_tac(&tac[b][pn-1][0]);            //bot right zone
  3587.                                 yb=get_tac(&tac[b][pn-1][1]);            //bot right zone
  3588.                                 xc=get_tac(&tac[b-1][pn-1][0]);                //bot zone
  3589.                                 yc=get_tac(&tac[b-1][pn-1][1]);                //bot zone
  3590.                             }
  3591.                         }
  3592.  
  3593.                         float xint_ab=xa+((xb-xa)*ABS(oy)/zone_hgt);
  3594.                         float xint_hc=x+((xc-x)*ABS(oy)/zone_hgt);
  3595.  
  3596.                         float yint_cb=yc+((yb-yc)*ABS(ox)/zone_wid);
  3597.                         float yint_ha=y+((ya-y)*ABS(ox)/zone_wid);
  3598.  
  3599.                         x=xint_hc+((xint_ab-xint_hc)*ABS(ox)/zone_wid);
  3600.                         y=yint_ha+((yint_cb-yint_ha)*ABS(oy)/zone_hgt);
  3601.                     }
  3602.                 }
  3603.             }
  3604.         }
  3605.  
  3606.         float xoff,yoff;
  3607.         if (flag)
  3608.         {
  3609.             if (flag==1)
  3610.             {
  3611.                 xoff=x-incident_x;
  3612.                 yoff=y-incident_y;
  3613.             }
  3614.             else
  3615.             {
  3616.                 xoff=(pitch_len-x)-incident_x;
  3617.                 yoff=(pitch_wid-y)-incident_y;
  3618.             }
  3619.         }
  3620.  
  3621.         switch(game_action)
  3622.         {
  3623.             float dist;
  3624. // Team A and B must be 10 yards away from ball!
  3625.             case(-1):
  3626.             case(1):
  3627.                 dist=calc_dist(xoff,yoff);
  3628.                 if (dist<prat*10)
  3629.                 {
  3630.                     if (flag==1)
  3631.                     {
  3632.                         x=incident_x+(xoff*(INCIDENT_DIST)/dist);
  3633.                         y=incident_y+(yoff*(INCIDENT_DIST)/dist);
  3634.                     }
  3635.                     else
  3636.                     {
  3637.                         x=pitch_len-(incident_x+(xoff*(INCIDENT_DIST)/dist));
  3638.                         y=pitch_wid-(incident_y+(yoff*(INCIDENT_DIST)/dist));
  3639.                     }
  3640.                 }
  3641.                 break;
  3642.  
  3643. // Team A and B must be 10 yards away from ball and outside penalty box!
  3644.             case(2):
  3645.                 if (ballx<cntspot_x)
  3646.                     if (flag==1)
  3647.                         x=prat*19;
  3648.                     else
  3649.                         x=pitch_len-(prat*19);
  3650.                 else
  3651.                     if (flag==1)
  3652.                         x=pitch_len-(prat*19);        // On edge of 18 yard box!
  3653.                     else
  3654.                         x=prat*19;
  3655.  
  3656.                 if (flag==1)
  3657.                 {
  3658.                     xoff=x-incident_x;
  3659.                     yoff=y-incident_y;
  3660.                 }
  3661.                 else
  3662.                 {
  3663.                     xoff=(pitch_len-x)-incident_x;
  3664.                     yoff=(pitch_wid-y)-incident_y;
  3665.                 }
  3666.  
  3667.                 dist=calc_dist(xoff,yoff);
  3668.                 if (dist<prat*10)
  3669.                 {
  3670.                     if (flag==1)
  3671.                     {
  3672.                         x=incident_x+(xoff*(INCIDENT_DIST)/dist);
  3673.                         y=incident_y+(yoff*(INCIDENT_DIST)/dist);
  3674.                     }
  3675.                     else
  3676.                     {
  3677.                         x=pitch_len-(incident_x+(xoff*(INCIDENT_DIST)/dist));
  3678.                         y=pitch_wid-(incident_y+(yoff*(INCIDENT_DIST)/dist));
  3679.                     }
  3680.                 }
  3681.                 break;
  3682.         }
  3683.     }
  3684. }
  3685.  
  3686. /******************************************************************************
  3687. *****************************************************************************/
  3688.  
  3689. void find_zonal_target(match_player *player,float px,float py)
  3690. {
  3691.     if (!player->draw_me && player->tm_y>0 && player->tm_y<pitch_wid)
  3692.         player->draw_me=TRUE;
  3693.  
  3694.     int ball_zn;
  3695.     char f;
  3696.     float tx,ty,sx,sy;
  3697.     if ((player->tm_player==KP_A) || (player->tm_player==KP_B))
  3698.     {
  3699.  
  3700. /****************
  3701. ** Goal-Keeper    **
  3702. ****************/
  3703.  
  3704.         if (player->tm_player==KP_A)
  3705.         {
  3706.             if ((dead_ball_cnt) && (gkick_taker==KP_A) && 
  3707.                 ((match_mode==GOAL_KICK_TL) || (match_mode==GOAL_KICK_BL)))
  3708.             {
  3709. // Taking Goal Kick!
  3710.                 tx=taker_x;
  3711.                 ty=taker_y;
  3712.                 set_there_flags(gkick_taker);
  3713.             }
  3714.             else
  3715.             {
  3716.                 if (match_mode==DF_KICK_B && men_in_wall>2)
  3717.                 {
  3718. // Get keeper in position behind last man in wall...
  3719.                     tx=keeper_pos_x;
  3720.                     ty=keeper_pos_y;
  3721.                 }
  3722.                 else
  3723.                 {
  3724.                     if (match_mode==SWAP_ENDS)
  3725.                     {
  3726.                         get_target(1,ball_zn,zone1_x,zone1_y,(player->tm_player)-1,tx,ty,match_tactics1);
  3727.                     }
  3728.                     else
  3729.                     {
  3730.                         if (ball_poss>=12 && match_mode!=PEN_KICK_B && !penalty_shot)
  3731.                         {
  3732. // Opponent_has ball...
  3733.                             float d=calc_dist(ballx,bally-cntspot_y);        // distance of centre of goal to ball!
  3734.                             if ((keeper_a_in_box) && (d<CLOSE_ANG_DIST+(prat*player->tm_vis)/8))
  3735. // Shut the door...
  3736.                                 close_angle(player,d,tx,ty);            // Close down the angle of shot.
  3737.                             else
  3738.                             {
  3739.                                 tx=KP_OFFLINE;
  3740.                                 ty=cntspot_y-1;
  3741.                             }
  3742.                         }
  3743.                         else
  3744.                         {
  3745.                             if (match_mode==PEN_KICK_B)
  3746.                                 tx=0;
  3747.                             else
  3748.                                 if (shot_pending && penalty_shot)
  3749.                                     tx=0;
  3750.                                 else
  3751.                                     tx=KP_OFFLINE;
  3752.  
  3753.                             ty=cntspot_y-1;
  3754.                         }
  3755.                     }
  3756.                 }
  3757.             }
  3758.         }
  3759.         else            
  3760.         {
  3761.              if ((dead_ball_cnt) && (gkick_taker==KP_B) && 
  3762.              ((match_mode==GOAL_KICK_TR) || (match_mode==GOAL_KICK_BR)))
  3763.              {
  3764. // Taking Goal Kick!
  3765.                 tx=taker_x;
  3766.                 ty=taker_y;
  3767.                 set_there_flags(gkick_taker);
  3768.             }
  3769.             else
  3770.             {
  3771.                 if (match_mode==DF_KICK_A && men_in_wall>2)
  3772.                 {
  3773. // Get keeper in position behind last man in wall...
  3774.                     tx=keeper_pos_x;
  3775.                     ty=keeper_pos_y;
  3776.                 }
  3777.                 else
  3778.                 {
  3779.                     if (match_mode==SWAP_ENDS)
  3780.                     {
  3781.                         get_target(2,ball_zn,zone2_x,zone2_y,(player->tm_player)-12,tx,ty,match_tactics2);
  3782.                         tx=pitch_len-tx;
  3783.                         ty=pitch_wid-ty;
  3784.                     }
  3785.                     else
  3786.                     {
  3787.                         if (ball_poss && ball_poss<12 && match_mode!=PEN_KICK_A && !penalty_shot)
  3788.                         {
  3789. // Opponent_has ball...
  3790.                             float d=calc_dist(pitch_len-ballx,bally-cntspot_y);        // distance of centre of goal to ball!
  3791.                             if ((keeper_b_in_box) && (d<CLOSE_ANG_DIST+(prat*player->tm_vis)/8))
  3792. // Shut the door...
  3793.                                 close_angle(player,d,tx,ty);            // Close down the angle of shot.
  3794.                             else
  3795.                             {
  3796.                                 tx=pitch_len-KP_OFFLINE;
  3797.                                 ty=cntspot_y-1;
  3798.                             }
  3799.                         }
  3800.                         else
  3801.                         {
  3802.                             if (match_mode==PEN_KICK_A)
  3803.                                 tx=pitch_len-1;
  3804.                             else
  3805.                                 if (shot_pending && penalty_shot)
  3806.                                     tx=pitch_len-1;
  3807.                                 else
  3808.                                     tx=pitch_len-KP_OFFLINE;
  3809.  
  3810.                             ty=cntspot_y-1;
  3811.                         }
  3812.                     }
  3813.                 }
  3814.             }
  3815.         }
  3816.  
  3817.         tx=tx-px;
  3818.         ty=ty-py;
  3819.         char s;
  3820.         float d=calc_dist(tx,ty);
  3821.         if ((player->face_dir!=get_dir(tx,ty)) &&
  3822.             (((player->go_step) && (d<STEP_RANGE*2))
  3823.             || ((!player->go_step) && (d<STEP_RANGE))))
  3824. // Calculate single move.
  3825.         {
  3826.             s=TRUE;
  3827.             if (player->tm_rate>=d*32)
  3828.             {
  3829.                 sx=tx;
  3830.                 sy=ty;
  3831.             }
  3832.             else
  3833.             {
  3834.                 sx=(player->tm_rate/(d*32))*tx;
  3835.                 sy=(player->tm_rate/(d*32))*ty;
  3836.             }
  3837.         }
  3838.         else
  3839.         {
  3840. // Calculate single move.
  3841.             if (player->tm_rate>=d*16)
  3842.             {
  3843.                 sx=tx;
  3844.                 sy=ty;
  3845.             }
  3846.             else
  3847.             {
  3848.                 sx=(player->tm_rate/(d*16))*tx;
  3849.                 sy=(player->tm_rate/(d*16))*ty;
  3850.             }
  3851.         }
  3852.  
  3853.         init_run_act(player,tx+px,ty+py,TRUE);
  3854.         if (player->tm_act==RUN_ACT)
  3855.         {
  3856.             go_forward(player);
  3857.             player->go_cnt=0;
  3858.         }                    
  3859.     }
  3860.     else
  3861.     {
  3862.  
  3863. /***********
  3864. ** PLAYER **        
  3865. ***********/
  3866.  
  3867.         if (!player->int_cnt)
  3868.         {
  3869.             if (player->tm_player<12)            // Team A?
  3870.             {
  3871.                 if ((ball_zone1<32) && (last_touch<12) && (last_touch!=0))    // Team A. in possession?
  3872.                     ball_zn=32;
  3873.                 else
  3874.                     ball_zn=0;
  3875.                 ball_zn+=ball_zone1;
  3876.                 get_target(1,ball_zn,zone1_x,zone1_y,(player->tm_player)-1,tx,ty,match_tactics1);
  3877.  
  3878.                 tx=tx-px;
  3879.                 ty=ty-py;
  3880.                 float d=calc_dist(tx,ty);
  3881.                 if ((player->tm_act==RUN_ACT) ||
  3882.                     (d>GO_TO_POS_DIST && player->tm_act!=RUN_ACT))
  3883.                 {
  3884.                     char s;
  3885.                     float d=calc_dist(tx,ty);
  3886.                     if ((player->face_dir!=get_dir(tx,ty)) &&
  3887.                         (((player->go_step) && (d<STEP_RANGE*2))
  3888.                         || ((!player->go_step) && (d<STEP_RANGE))))
  3889.  
  3890.                     {
  3891.                         s=TRUE;
  3892.                     }
  3893.                     else
  3894.                     {
  3895.                         s=FALSE;
  3896.                     }
  3897.  
  3898.                     init_run_act(player,tx+px,ty+py,TRUE);
  3899.                     if (player->tm_act==RUN_ACT)
  3900.                     {
  3901.                         go_forward(player);
  3902.                           player->go_cnt=0;
  3903.                     }
  3904.                 }
  3905.                 else
  3906.                 {
  3907. // There already!
  3908.                     if (player->int_move==I_THROW)
  3909.                     {
  3910.                         player->int_cnt=1;
  3911.                         reset_ideas(player);
  3912.                     }
  3913.                 }
  3914.             }
  3915.             else
  3916.             {
  3917.                 if ((ball_zone2<32) && last_touch>11)                                // Team B. in possession?
  3918.                     ball_zn=32;
  3919.                 else
  3920.                     ball_zn=0;
  3921.                 ball_zn+=ball_zone2;
  3922.                 get_target(2,ball_zn,zone2_x,zone2_y,(player->tm_player)-12,tx,ty,match_tactics2);
  3923.                 tx=(pitch_len-tx)-px;
  3924.                 ty=(pitch_wid-ty)-py;
  3925.                 float d=calc_dist(tx,ty);
  3926.                 if ((player->tm_act==RUN_ACT) ||
  3927.                     (d>GO_TO_POS_DIST && player->tm_act!=RUN_ACT))
  3928.                 {
  3929.                     char s;
  3930.                     float d=calc_dist(tx,ty);
  3931.  
  3932.                     if ((player->face_dir!=get_dir(tx,ty)) &&
  3933.                         ((player->go_step) && (d<STEP_RANGE*2))
  3934.                         || ((!player->go_step) && (d<STEP_RANGE)))
  3935.  
  3936. // Calculate single move.
  3937.                     {
  3938.                         s=TRUE;
  3939.                     }
  3940.                     else
  3941.                     {
  3942.                         s=FALSE;
  3943.                     }
  3944.                     init_run_act(player,tx+px,ty+py,TRUE);
  3945.                     if (player->tm_act==RUN_ACT)
  3946.                     {
  3947.                         go_forward(player);
  3948.                         player->go_cnt=0;
  3949.                     }
  3950.                 }
  3951.                 else
  3952.                 {
  3953. // There already!
  3954.                     if (player->int_move==I_THROW)
  3955.                     {
  3956.                         player->int_cnt=1;
  3957.                         reset_ideas(player);
  3958.                     }
  3959.                 }
  3960.             }
  3961.         }
  3962.     }
  3963. }
  3964.  
  3965. /******************************************************************************
  3966. *****************************************************************************/
  3967.  
  3968. // Return closest guy to the predicted path of ball who is not busy!
  3969. // p_num = first player in team.
  3970.  
  3971. int get_near_path(int p_num,int not_busy)
  3972. {
  3973.     int near_guy=0, closest=10000;
  3974.     int t=0;
  3975.  
  3976. // Get average position of ball...
  3977.  
  3978.     float x1=ball_pred_tab[t][0];
  3979.     float y1=ball_pred_tab[t][1];
  3980.     float z1=ball_pred_tab[t][2];
  3981.  
  3982.     float px,py;
  3983.     short points=0;
  3984.     float x=-1000;
  3985.     float y=0;
  3986.     float z=0;
  3987.     float    d;
  3988.  
  3989.     for (int b=1; b<40; b++)
  3990.     {
  3991.         if (x<-999 && ball_pred_tab[b][2]<PLAYER_HEIGHT+4)
  3992.         {
  3993.             x=ball_pred_tab[b][0]-x1;
  3994.             y=ball_pred_tab[b][1]-y1;
  3995.         }
  3996.         else
  3997.         {
  3998.             if (x>-999)
  3999.             {
  4000.                 x+=ball_pred_tab[b][0]-x1;
  4001.                 y+=ball_pred_tab[b][1]-y1;
  4002.                 points++;
  4003.             }
  4004.         }
  4005.     }
  4006.  
  4007.     if (points)
  4008.     {
  4009.         x=x/points;
  4010.         y=y/points;
  4011.         x+=x1;
  4012.         y+=y1;
  4013.     }
  4014.     else
  4015.     {
  4016.         x=ball_pred_tab[40][0];
  4017.         y=ball_pred_tab[40][1];
  4018.     }
  4019.  
  4020.     for (int i=p_num+10; i>=p_num; i--)
  4021.     {
  4022.         if (teams[i].tm_notme)
  4023.             teams[i].tm_notme--;        // he can't get there!
  4024.         else
  4025.         {
  4026.             if ((teams[i].tm_act<=TURN_ACT || (teams[i].tm_act==TACKLE_ACT && teams[i].control))
  4027.                  && ball_poss!=p_num+1)        //player is not busy!
  4028.             {
  4029.                 if ((!(teams[i].int_cnt)) || (not_busy))
  4030.                 {
  4031.                     px=teams[i].tm_x;
  4032.                     py=teams[i].tm_y;
  4033.  
  4034.                     d=calc_dist(px-x,py-y);
  4035.  
  4036.                     if (i==(KP_A-1) || i==(KP_B-1))
  4037.                     {
  4038. // Keeper only intercept if half as close as defender!
  4039.  
  4040.                         if (d*2<closest && closest>prat*2)
  4041.                         {
  4042.                             near_guy=i+1;                        //This guy is closer!
  4043.                             closest=d;
  4044.                         }
  4045.                     }
  4046.                     else
  4047.                     {
  4048.                         if (d<closest)
  4049.                         {
  4050.                             near_guy=i+1;                        //This guy is closer!
  4051.                             closest=d;
  4052.                         }
  4053.                     }
  4054.                 }
  4055.             }
  4056.         }
  4057.     }
  4058.     return(near_guy);
  4059. }
  4060.  
  4061. /******************************************************************************
  4062. *****************************************************************************/
  4063.  
  4064. // Return closest guy to the predicted path of ball who is not busy!
  4065. // p_num = first player in team.
  4066.  
  4067. int oget_near_path(int p_num,int not_busy)
  4068. {
  4069.     int near_guy=0, closest=10000;
  4070.     int t=first_bounce;
  4071.     if (t<0)
  4072.         t=0;
  4073.  
  4074. // Get average position of ball...
  4075.  
  4076.     float x1=ball_pred_tab[t][0];
  4077.     float y1=ball_pred_tab[t][1];
  4078.     float z1=ball_pred_tab[t][2];
  4079.  
  4080.     float px,py;
  4081.     short points=0;
  4082.     float x=0;
  4083.     float y=0;
  4084.     float z=0;
  4085.     float    d;
  4086.  
  4087.     for (int b=t+1; b<40; b++)
  4088.     {
  4089.         if (ball_pred_tab[b][2]<PLAYER_HEIGHT+4)
  4090.         {
  4091.             x+=ball_pred_tab[b][0]-x1;
  4092.             y+=ball_pred_tab[b][1]-y1;
  4093.             points++;
  4094.         }
  4095.     }
  4096.  
  4097.     if (points)
  4098.     {
  4099.         x=x/points;
  4100.         y=y/points;
  4101.         x+=x1;
  4102.         y+=y1;
  4103.     }
  4104.     else
  4105.     {
  4106.         x=ball_pred_tab[40][0];
  4107.         y=ball_pred_tab[40][1];
  4108.     }
  4109.  
  4110.     for (int i=p_num+10; i>=p_num; i--)
  4111.     {
  4112.         if (teams[i].tm_notme)
  4113.             teams[i].tm_notme--;        // he can't get there!
  4114.         else
  4115.         {
  4116.  
  4117.             if (teams[i].tm_act<=TURN_ACT && ball_poss!=p_num+1)        //player is not busy!
  4118.             {
  4119.                 if ((!(teams[i].int_cnt)) || (not_busy))
  4120.                 {
  4121.                     px=teams[i].tm_x;
  4122.                     py=teams[i].tm_y;
  4123.  
  4124.                     d=calc_dist(px-x,py-y);
  4125.  
  4126.                     if (i==(KP_A-1) || i==(KP_B-1))
  4127.                     {
  4128. // Keeper only intercept if half as close as defender!
  4129.  
  4130.                         if (d*2<closest && closest>prat*2)
  4131.                         {
  4132.                             near_guy=i+1;                        //This guy is closer!
  4133.                             closest=d;
  4134.                         }
  4135.                     }
  4136.                     else
  4137.                     {
  4138.                         if (d<closest)    
  4139.                         {
  4140.                             near_guy=i+1;                        //This guy is closer!
  4141.                             closest=d;
  4142.                         }
  4143.                     }
  4144.                 }
  4145.             }
  4146.         }
  4147.     }
  4148.     return(near_guy);
  4149. }
  4150.  
  4151. /******************************************************************************
  4152. *****************************************************************************/
  4153.  
  4154. void forward_joystick(match_player *p,float &x,float &y)
  4155. {
  4156.     x=p->go_txdis;
  4157.     y=p->go_tydis;
  4158.  
  4159.     if (ux)
  4160.     {
  4161. // Turn!
  4162.         float ta=(PI/12)*ux;
  4163.         float nx=x*cos(ta)-y*sin(ta);
  4164.         float ny=y*cos(ta)+x*sin(ta);
  4165.         x=nx;
  4166.         y=ny;
  4167.     }
  4168. }
  4169.  
  4170. /******************************************************************************
  4171.  *****************************************************************************/
  4172.  
  4173. void get_face_xy(int d,float &x,float &y)
  4174. {
  4175.     switch(d)
  4176.     {
  4177.         case(0):
  4178.             x=-UNIT;
  4179.             y=0;
  4180.             break;
  4181.     
  4182.         case(1):
  4183.             x=-DIAG;
  4184.             y=DIAG;
  4185.             break;
  4186.  
  4187.         case(2):
  4188.             x=0;
  4189.             y=UNIT;
  4190.             break;
  4191.     
  4192.         case(3):
  4193.             x=DIAG;
  4194.             y=DIAG;
  4195.             break;
  4196.  
  4197.         case(4):
  4198.             x=UNIT;
  4199.             y=0;
  4200.             break;
  4201.     
  4202.         case(5):
  4203.             x=DIAG;
  4204.             y=-DIAG;
  4205.             break;
  4206.  
  4207.         case(6):
  4208.             x=0;
  4209.             y=-UNIT;
  4210.             break;
  4211.     
  4212.         case(7):
  4213.             x=-DIAG;
  4214.             y=-DIAG;
  4215.             break;
  4216.     }
  4217. }
  4218.  
  4219. /******************************************************************************
  4220. *****************************************************************************/
  4221.  
  4222. int get_dir(float x,float y)
  4223. {
  4224.     int d=0;
  4225.     if (y>=0)
  4226.     {
  4227.         if (x>=0)
  4228.         {
  4229.             if (x>y)
  4230.             {
  4231.                 if (x>(y*2))
  4232.                     d=4;
  4233.                 else
  4234.                     d=3;
  4235.             }
  4236.             else
  4237.             {
  4238.                 if (y>(x*2))
  4239.                      d=2;
  4240.                 else
  4241.                     d=3;
  4242.             }
  4243.         }
  4244.         else
  4245.         {
  4246.             if (-x>y)
  4247.             {
  4248.                 if (-x>(y*2))
  4249.                     d=0;
  4250.                 else
  4251.                     d=1;
  4252.             }
  4253.             else
  4254.             {
  4255.                 if (y>(-x*2))
  4256.                     d=2;
  4257.                 else
  4258.                     d=1;
  4259.             }
  4260.         }
  4261.     }
  4262.     else
  4263.     {
  4264.         if (x>=0)
  4265.         {
  4266.             if (x>-y)
  4267.             {
  4268.                 if (x>(-y*2))
  4269.                     d=4;
  4270.                 else
  4271.                     d=5;
  4272.             }
  4273.             else
  4274.             {
  4275.                 if (-y>(x*2))
  4276.                      d=6;
  4277.                 else
  4278.                     d=5;
  4279.             }
  4280.         }
  4281.         else
  4282.         {
  4283.             if (-x>-y)
  4284.             {
  4285.                 if (-x>(-y*2))
  4286.                     d=0;
  4287.                 else
  4288.                     d=7;
  4289.             }
  4290.             else
  4291.             {
  4292.                 if (-y>(-x*2))
  4293.                     d=6;
  4294.                 else
  4295.                     d=7;
  4296.             }
  4297.         }
  4298.     }
  4299.     return(d);
  4300. }
  4301.  
  4302. /******************************************************************************
  4303. *****************************************************************************/
  4304.  
  4305. int angle_of_vis(match_player *player,int x,int y,float d,char cross=FALSE)
  4306. {
  4307.       float a;
  4308.     float xd=player->tm_xdis;
  4309.     float yd=player->tm_ydis;
  4310.     float d2=calc_dist(xd,yd);
  4311.     xd=xd/d2;
  4312.     yd=yd/d2;
  4313.     if (cross)
  4314.     {
  4315.         if (player->tm_player<12)
  4316. //    Team A...
  4317.         {
  4318.              if ((d/2>(MIN_PASS_DIST+(float)player->tm_pow/3.6)) && (x+player->tm_x>pitch_len-(prat*18)))
  4319.                 return(TRUE);
  4320.             else
  4321.                 return(FALSE);
  4322.         }
  4323.         else
  4324. //    Team B...
  4325.         {
  4326.              if ((d/2>(MIN_PASS_DIST+(float)player->tm_pow/3.6)) && (x+player->tm_x<(prat*18)))
  4327.                 return(TRUE);
  4328.             else
  4329.                 return(FALSE);
  4330.         }
  4331.     }
  4332.     if (set_piece_on)
  4333.         a=((x*setp_kick_x)+(y*setp_kick_y))/d;        // Joystick dir.
  4334.     else
  4335.         a=((x*xd)+(y*yd))/d;        // facing...
  4336.  
  4337.     if (a>=DIAG)
  4338.         return(TRUE);
  4339.     else
  4340.         return(FALSE);
  4341. }
  4342.  
  4343. /******************************************************************************
  4344. *****************************************************************************/
  4345.  
  4346. // Creates table of opponents round player within DRIB_DANGER_AREA.
  4347.  
  4348. void get_opp_dir_tab(int pnum)
  4349. {
  4350.     float dist=DRIB_DANGER_AREA+(prat*(((128-teams[pnum-1].tm_flair)/12)-5));
  4351.     drib_opps=0;
  4352.     int op=1;
  4353.     if (pnum<12)
  4354.         op=12;
  4355.     float x,y,d,dif;
  4356.  
  4357.     for (int p=op; p<op+11; p++)
  4358.     {
  4359. // Vectors for opp. to ball...
  4360.  
  4361.         x=(teams[p-1].tm_x-ballx)/teams[p-1].tm_dist;
  4362.         y=(teams[p-1].tm_y-bally)/teams[p-1].tm_dist;
  4363.         
  4364. // Calculate difference range of 2(ahead) to 0(behind)...
  4365.         dif=1+((teams[pnum-1].tm_xdis*x)+(teams[pnum-1].tm_ydis*y));
  4366.         d=dist/4+(dist*dif*3/8);
  4367.  
  4368.         if (teams[p-1].guy_on && teams[p-1].tm_dist<=d && teams[p-1].tm_act<TURN_ACT)
  4369.         {
  4370. //            if (!(teams[p-1].tm_act==TACKLE_ACT && ((teams[p-1].go_txdis*teams[p-1].go_tydis)<4)))
  4371.             {
  4372.                 opp_dir_tab[drib_opps][0]=teams[p-1].tm_x;
  4373.                 opp_dir_tab[drib_opps][1]=teams[p-1].tm_y;
  4374.                 opp_dir_tab[drib_opps][2]=1-(teams[pnum-1].tm_dist/d);    // Attack potential
  4375.                 drib_opps++;
  4376.             }
  4377.         }
  4378.     }
  4379. }
  4380.  
  4381. /******************************************************************************
  4382. *****************************************************************************/
  4383.  
  4384. // Count the number of opponents around player (pnum)!
  4385.  
  4386. int opp_around(int x,int y,int pnum)
  4387. {
  4388.     int op=1;
  4389.     int d;
  4390.     int opponents=0;
  4391.     if (pnum<12)
  4392.         op=12;
  4393.     for (int p=op; p<op+11; p++)
  4394.     {
  4395.         if (teams[p-1].guy_on)
  4396.         {
  4397.             d=calc_dist(teams[p-1].tm_x-x,teams[p-1].tm_y-y);
  4398.             if (ball_poss==KP_A || ball_poss==KP_B)
  4399.             {
  4400.                 if (d<=(DANGER_AREA*1.6))
  4401.                     opponents++;
  4402.             }
  4403.             else
  4404.             {
  4405.                 if (d<=DANGER_AREA)
  4406.                     opponents++;
  4407.             }
  4408.         }
  4409.     }
  4410.     return(opponents);
  4411. }
  4412.  
  4413. /******************************************************************************
  4414. *****************************************************************************/
  4415.  
  4416. // Count the number of opponents around player (pnum)!
  4417.  
  4418. // This function specific to keeper passing out...
  4419.  
  4420. int kopp_around(int x,int y,int pnum)
  4421. {
  4422.     int op=1;
  4423.     int d;
  4424.     int opponents=0;
  4425.     if (pnum<12)
  4426.         op=12;
  4427.     for (int p=op; p<op+11; p++)
  4428.     {
  4429.         if (teams[p-1].guy_on)
  4430.         {
  4431.             d=calc_dist(teams[p-1].tm_x-x,teams[p-1].tm_y-y);
  4432.             if (d<=(DANGER_AREA*2))
  4433.                 opponents++;
  4434.         }
  4435.     }
  4436.     return(opponents);
  4437. }
  4438.  
  4439. /******************************************************************************
  4440. *****************************************************************************/
  4441.  
  4442. float facing_opp(match_player *player,short opp)
  4443. {
  4444.     float xd=player->tm_xdis;
  4445.     float yd=player->tm_ydis;
  4446.     float xo=teams[opp-1].tm_xdis;
  4447.     float yo=teams[opp-1].tm_ydis;
  4448.     float a=((xo*xd)+(yo*yd));
  4449.     return(a);
  4450. }
  4451.  
  4452. /******************************************************************************
  4453. *****************************************************************************/
  4454.  
  4455. void player_ints(match_player *player)
  4456. {
  4457.     if (((player->tm_act==TACKLE_ACT && player->go_cnt>EFFECTIVE_TACK)
  4458.         || (player->tm_act==STEAL_ACT && player->tm_frm>0.4 && player->tm_frm<0.6))
  4459.         && (!dead_ball_cnt) && (!just_scored))
  4460.     {
  4461.         float x,y,z;
  4462.         float dir;
  4463.         short chance;
  4464.         for (int i=1; i<=players; i++)
  4465.         {
  4466.             if (teams[i-1].tm_act<=TURN_ACT)
  4467.             {
  4468.                 x=player->tm_x-teams[i-1].tm_x;
  4469.                 y=player->tm_y-teams[i-1].tm_y;
  4470.                 z=player->tm_y-teams[i-1].tm_y;
  4471.                 if ((calc_dist(x,y)<=PLAYER_SIZE) && (z<PLAYER_HEIGHT/3))
  4472.                 {
  4473. // If the tackling player comes in from behind or the side
  4474. // then he has a greater chance of bringing the opponent down!
  4475.                     dir=facing_opp(player,i);
  4476.                     chance=seed/(dir+2);
  4477.  
  4478.                     if (chance<(42+((player->tm_pow-teams[i-1].tm_pow)/3)))
  4479.                     {
  4480. // Crunching tackle...
  4481.                         init_fall(&teams[i-1]);
  4482. //                        if ((!player->go_step) && ((player_num<12 && i>11) || (player_num>11 && i<12)))
  4483.                         if (((player_num<12 && i>11) || (player_num>11 && i<12)))
  4484.                         {
  4485. // He is in opposing team!
  4486. // He hasn't made contact with ball...
  4487. // Therefore a foul has been commited...
  4488.                             man_down=calc_dist(player->go_txdis,
  4489.                                                      player->go_tydis);
  4490.  
  4491.                             init_foul(player->tm_player,TRUE);    // pass no. of fouler.
  4492.  
  4493. // Man appeals for f.k...
  4494.                             init_speech(i,SAY_REF,REAL_SPEED);
  4495.                         }
  4496.                     }
  4497.                     else
  4498. // Ride over tackle...
  4499.                         if (player->tm_act!=STEAL_ACT)
  4500.                             init_jump_act(&teams[i-1],TRUE,TRUE);
  4501.                 }
  4502.             }
  4503.         }
  4504.     }
  4505. }
  4506.  
  4507. /*****************************************************************************
  4508. *****************************************************************************/
  4509.  
  4510. char cross_angle(float xd,float yd,float x,float y)
  4511. {
  4512.     float a=angle_to_xy(xd,yd,x,y);
  4513.     if (a>-0.174 && a<0.707)
  4514. // In 55 degree threshold (100 -> 45)...
  4515.     {
  4516.         if ((xd*y)>(yd*x))
  4517.             return(1);
  4518.         else
  4519.              return(2);
  4520.     }
  4521.     else
  4522.         return(0);
  4523. }
  4524.  
  4525. /*****************************************************************************
  4526. *****************************************************************************/
  4527.  
  4528. void new_interceptor(int p)
  4529. {
  4530.     if (p<12)
  4531.     {
  4532. // Team A...
  4533.         if (interceptor_a)
  4534.         {
  4535.             reset_ideas(&teams[interceptor_a-1]);
  4536.         }
  4537.  
  4538.         receiver_a=p;
  4539.         near_path_a=p;        // Fake passee as nearest!
  4540.     }
  4541.     else
  4542.     {
  4543. // Team B...
  4544.         if (interceptor_b)
  4545.         {
  4546.             reset_ideas(&teams[interceptor_b-1]);
  4547.         }
  4548.  
  4549.         receiver_b=p;
  4550.         near_path_b=p;        // Fake passee as nearest!
  4551.     }
  4552.  
  4553. #ifdef EURO96        // 1-2 Pass.
  4554.     if (uf1)
  4555. // Force receiver to return ball again to complete 1-2!
  4556.     {
  4557.         return_12=p;
  4558.     }
  4559.     else
  4560.     {
  4561.         return_12=FALSE;
  4562.         reselect();            // Can control receiver.
  4563.     }
  4564. #else
  4565.     reselect();
  4566. #endif
  4567. }
  4568.  
  4569. /*****************************************************************************
  4570. *****************************************************************************/
  4571.  
  4572. int pass_ahead(int ps,float &x,float &y,float &pass_speed,float &end_speed,char cross)
  4573. {
  4574.     int i=0;
  4575.     int t;
  4576.     float a,b,s;
  4577.     a=x;
  4578.     b=y;
  4579.     float xd,yd,dd;
  4580.     int extra;
  4581.  
  4582.     if (ball_limbo_on)
  4583.         extra=((ball_limbo_c-teams[ball_limbo_p-1].tm_frm)/teams[ball_limbo_p-1].tm_fstep)-1;
  4584.     else
  4585.         extra=0;
  4586.  
  4587. // Get Targets movement...
  4588.     xd=teams[ps-1].go_txdis;
  4589.     yd=teams[ps-1].go_tydis;
  4590.  
  4591.     for (i=1; i<40; i++)
  4592.     {
  4593.         a+=xd;
  4594.         b+=yd;        // Inc running time
  4595.  
  4596.         dd=calc_dist(a,b);
  4597.  
  4598.         if (cross || dd>LOW_PASS_DIST || chip_pass)
  4599.         {
  4600. // In air...
  4601.             pass_speed=end_speed+4+(dd*(1-AIR_FRICTION));
  4602.             t=(log((end_speed+4)/pass_speed))/(log(AIR_FRICTION));
  4603.         }
  4604.         else
  4605.         {
  4606. // On grnd...
  4607.             pass_speed=end_speed+(dd*(1-GRND_FRICTION));
  4608.             t=(log(end_speed/pass_speed))/(log(GRND_FRICTION));
  4609.         }
  4610.  
  4611.         if (t<=(i-extra))
  4612.             i=1000;                        // Intersection with run here...
  4613.     }
  4614.  
  4615.     if (i>=1000)
  4616.     {
  4617. // successfull intersection....
  4618.         x=a+xd;
  4619.         y=b+yd;        // new offsets...
  4620.  
  4621.         if ((x+ballx)<0)
  4622.             x=prat-ballx;
  4623.  
  4624.         if ((x+ballx)>pitch_len)
  4625.             x=(pitch_len-prat)-ballx;
  4626.  
  4627.         if ((y+bally)<0)
  4628.             y=prat-bally;
  4629.  
  4630.         if ((y+bally)>pitch_wid)
  4631.             y=(pitch_wid-prat)-bally;
  4632.  
  4633.         if (dd>LOW_PASS_DIST)
  4634.             ball_inair=TRUE;
  4635.     }
  4636.  
  4637.     return(t);
  4638. }
  4639.  
  4640. /*****************************************************************************
  4641. *****************************************************************************/
  4642.  
  4643. void choose_pass(int ps,float &x,float &y,float &pass_speed,float &end_speed,char cross)
  4644. {
  4645.     float tx,ty,d;
  4646.     if (cross)
  4647.     {
  4648. // Cross it ahead of him towards opponents goal...
  4649.         if (ps<12)
  4650. // Team B's Goal!
  4651.         {
  4652.             tx=pitch_len-teams[ps-1].tm_x;
  4653.             ty=cntspot_y-teams[ps-1].tm_y;
  4654.         }
  4655.         else
  4656. // Team A's Goal!
  4657.         {
  4658.             tx=-teams[ps-1].tm_x;
  4659.             ty=cntspot_y-teams[ps-1].tm_y;
  4660.         }
  4661.  
  4662.         if ((tx<=prat && ps<12) || (tx>-prat && ps>11))
  4663.         {
  4664. // Close to goal-line (straight to him instead!)...
  4665.             init_stand_act(&teams[ps-1]);
  4666.             int t=pass_ahead(ps,x,y,pass_speed,end_speed,cross);            // Obviously he isn't moving so it will go straight to him!
  4667.         }
  4668.         else
  4669.         {
  4670. // Target aimed ahead of player towards goal...
  4671.             d=calc_dist(tx,ty);
  4672.             x+=tx*prat/d;
  4673.             y+=ty*prat/d;
  4674.             init_stand_act(&teams[ps-1]);
  4675.               pass_ahead(ps,x,y,pass_speed,end_speed,cross);
  4676.         }
  4677.     }
  4678.     else
  4679.     {
  4680.         if (((((ps<12 && teams[ps-1].go_txdis>0) || (ps>11 && teams[ps-1].go_txdis<0))
  4681.              && teams[ps-1].tm_act==RUN_ACT)))
  4682.         {
  4683. // Pass ahead...
  4684.               pass_ahead(ps,x,y,pass_speed,end_speed,cross);
  4685.         }
  4686.         else
  4687.         {
  4688.             init_stand_act(&teams[ps-1]);
  4689.             int t=pass_ahead(ps,x,y,pass_speed,end_speed,cross);            // Obviously he isn't moving so it will go straight to him!
  4690.         }
  4691.     }
  4692. }
  4693.  
  4694. /*****************************************************************************
  4695. *****************************************************************************/
  4696.  
  4697. void pass_ball(int ps,char cross)
  4698. {
  4699.     inc_pass(ball_poss);
  4700.  
  4701.     receiver_a=FALSE;
  4702.     receiver_b=FALSE;
  4703.  
  4704.     float x,y;
  4705.     float d;
  4706.     int t;
  4707.  
  4708. // Speed of ball at target!
  4709.     
  4710.     float end_speed;
  4711.     float pass_speed;
  4712.  
  4713.     if (cross)
  4714.     {
  4715.         new_shot(ball_poss);        // Treat crosses as shots at goal!
  4716. // Hit it harder to cross it in...
  4717.         end_speed=7;
  4718.     }
  4719.     else
  4720.         end_speed=5;
  4721.  
  4722.     if (ps<=0)
  4723.     {
  4724.         comm_pass=0;        // Default short pass...
  4725.  
  4726. // Must pass but no-one to pass to!
  4727.         if (teams[ball_poss-1].tm_act==THROW_ACT)
  4728.         {
  4729.             x=teams[ball_poss-1].tm_xdis*140;        // Far forward!
  4730.             y=teams[ball_poss-1].tm_ydis*140;
  4731.         }
  4732.         else
  4733.         {
  4734.             if (!user_controlled)
  4735.             {
  4736.                 switch(must_pass)
  4737.                 {
  4738.                     case(NORMAL_PLAY):
  4739.                         x=teams[ball_poss-1].tm_xdis*10;        // Tap forward!
  4740.                         y=teams[ball_poss-1].tm_ydis*10;
  4741.                         end_speed=(actual_spd(&teams[ball_poss-1]))+0.8;
  4742.                         break;
  4743.  
  4744.                     case(CORNER_TR):
  4745.                     case(CORNER_BR):
  4746.                         x=pitch_len-(prat*15)-ballx;
  4747.                         y=cntspot_y-bally;
  4748.                         break;
  4749.  
  4750.                     case(CORNER_TL):
  4751.                     case(CORNER_BL):
  4752.                         x=(prat*15)-ballx;
  4753.                         y=cntspot_y-bally;
  4754.                         break;
  4755.  
  4756.                     case(CENTRE_A):
  4757.                     case(CENTRE_B):
  4758.                         x=cntspot_x-ballx;
  4759.                         y=cntspot_y-bally;
  4760.                         break;
  4761.  
  4762.                     case(IF_KICK_A):
  4763.                     case(IF_KICK_B):
  4764.                     case(DF_KICK_A):
  4765.                     case(DF_KICK_B):
  4766.                         x=setp_kick_x*160;        // Pass forward!
  4767.                         y=setp_kick_y*160;
  4768.                         break;
  4769.                 }
  4770.             }
  4771.             else
  4772.             {
  4773.                 if (spec_kick_type==SPACT_HPASS || spec_kick_type==SPACT_DPASS
  4774.                      || spec_kick_type==SPACT_FPASS || spec_kick_type==SPACT_TEE_UP)
  4775.                 {
  4776. // User set-piece actions which should have been for team-mates...
  4777.                     if (chip_pass)
  4778.                     {
  4779.                           x=setp_kick_x*(prat*16);
  4780.                           y=setp_kick_y*(prat*16);
  4781.                     }
  4782.                     else
  4783.                     {
  4784.                           x=setp_kick_x*(prat*14);
  4785.                           y=setp_kick_y*(prat*14);
  4786.                     }
  4787.  
  4788.                     d=calc_dist(x,y);
  4789.                 }
  4790.  
  4791.                 if (spec_kick_type==SPACT_GRND)
  4792.                 {
  4793.                       x=setp_kick_x*(f2_down*prat);
  4794.                       y=setp_kick_y*(f2_down*prat);
  4795.                     d=calc_dist(x,y);
  4796.                 }
  4797.             }
  4798.         }
  4799.         d=calc_dist(x,y);
  4800.     }
  4801.  
  4802.     if (ps>0)
  4803.     {
  4804.         x=teams[ps-1].tm_x-ballx;
  4805.         y=teams[ps-1].tm_y-bally;
  4806.         d=calc_dist(x,y);
  4807.  
  4808.         comm_pass=(int)(d/(LONG_PASS_DIST));
  4809.  
  4810.         if (want_pass==ps)
  4811.         {
  4812. // team-mate cannot stop!
  4813.             pass_ahead(ps,x,y,pass_speed,end_speed,cross);
  4814.         }
  4815.         else
  4816.         {
  4817.             choose_pass(ps,x,y,pass_speed,end_speed,cross);
  4818.         }
  4819.  
  4820.         d=calc_dist(x,y);
  4821.     }
  4822.  
  4823. // Get acuracy offsets!
  4824.  
  4825.     float ac1,ac2;
  4826.  
  4827.     af_randomize();
  4828.  
  4829.     if ((ps>0) && (ps!=KP_A) && (ps!=KP_B) && want_pass!=ps)
  4830. // He is passing to an on-the-field player...
  4831.     {
  4832. // ac1=Direction offset!
  4833.         ac1=((rand_range(128-teams[ball_poss-1].tm_ac))*PASS_ACC_ARC)*D2RAD;
  4834.  
  4835. // ac2=Power offset!
  4836.         ac2=((float)(rand_range(128-teams[ball_poss-1].tm_ac)))/32;
  4837.  
  4838.         if (seed&64)
  4839.             ac1=-ac1;
  4840.     }
  4841.     else
  4842.     {
  4843.         ac1=0;
  4844.         ac2=0;
  4845.     }
  4846.  
  4847.     if (!match_info.GameType)
  4848.     {
  4849. // Arcade Mode...(Passing is always accurate!)
  4850.         ac1=0;
  4851.         ac2=0;
  4852.     }
  4853.  
  4854.     float nx,ny,ox,oy;
  4855.     
  4856.     ox=x/d;
  4857.     oy=y/d;
  4858.  
  4859.     nx=(ox*cos(ac1))-(oy*sin(ac1));
  4860.     ny=(oy*cos(ac1))+(ox*sin(ac1));
  4861.  
  4862. // New Target (x,y)!
  4863.     x=nx*d;
  4864.     y=ny*d;
  4865.  
  4866.     end_speed-=ac2;
  4867.  
  4868.     ball_zspin=0;
  4869.     ball_xyspin=0;
  4870.     full_xyspin=0;
  4871.     swerve=FALSE;
  4872.  
  4873.     if ((pass_type!=9) && ((ball_in_hands) || (heading_ball)))
  4874.     {
  4875. // need to throw ball!
  4876.         heading_ball=FALSE;
  4877.         ball_inair=TRUE;
  4878.         pass_speed=end_speed+2+(d*(1-AIR_FRICTION));
  4879.         ballxdis=pass_speed*x/d;
  4880.         ballydis=pass_speed*y/d;
  4881.  
  4882.         t=(log((end_speed+2)/pass_speed))/(log(AIR_FRICTION));
  4883.         if (!t)
  4884.             t=1;
  4885.  
  4886.         if (chip_pass)
  4887. // Aim for head...
  4888.             ballzdis=((PLAYER_HEIGHT-ballz)/t)+(t/2)*gravity;
  4889.         else
  4890.             ballzdis=(t/2)*gravity-(ballz/t);
  4891.  
  4892.         ball_in_hands=FALSE;
  4893. // Stop run!
  4894.         if (teams[ball_poss-1].tm_act==RUN_ACT)
  4895.             teams[ball_poss-1].go_cnt=0;
  4896.  
  4897.         launch_ball(1);            // Set up spin vector.
  4898.         cannot_pick_up=-ball_poss;
  4899.     }
  4900.     else
  4901.     {
  4902.         if (pass_type==-1 || pass_type==16 || pass_type==17 ||
  4903.             chip_pass)
  4904.         {
  4905. // need to chip ball!
  4906.             ball_inair=TRUE;
  4907.  
  4908.             if ((ps<=0) && (chip_pass))
  4909. // Forced chip forward...
  4910.             {
  4911.                 if (spec_kick_type==SPACT_CHIP)
  4912.                 {
  4913. // Use user power setting...
  4914.                     ballxdis=setp_bxd;
  4915.                     ballydis=setp_byd;
  4916.                     ballzdis=setp_bzd;
  4917.                 }
  4918.                 else
  4919.                 {
  4920.                     ballxdis=4*x/d;
  4921.                     ballydis=4*y/d;
  4922.                     ballzdis=6;
  4923.                 }
  4924.                 cannot_pick_up=ball_poss;
  4925.             }
  4926.             else
  4927.             {
  4928. // In air to team-mate...
  4929.                 pass_speed=end_speed+4+(d*(1-AIR_FRICTION));
  4930.                 t=(log((end_speed+4)/pass_speed))/(log(AIR_FRICTION));
  4931.  
  4932.                 ballxdis=pass_speed*x/d;
  4933.                 ballydis=pass_speed*y/d;
  4934.                 if (t<0.1)
  4935.                     t=1;
  4936.  
  4937.                 cannot_pick_up=ball_poss;
  4938.  
  4939.                 if (chip_pass)
  4940. // Aim for head...
  4941.                     ballzdis=((PLAYER_HEIGHT-ballz)/t)+(t/2)*gravity;
  4942.                 else
  4943.                     ballzdis=(t/2)*gravity-(ballz/t);
  4944.  
  4945.                 if (cross)
  4946.                 {
  4947.                     ballzdis=((PLAYER_HEIGHT-6-ballz)/t)+(t/2)*gravity;
  4948.                 }
  4949.  
  4950.                 if (ballzdis>14)
  4951.                     ballzdis=14;
  4952.             }
  4953.  
  4954.             char angle=0;
  4955.  
  4956.             launch_ball(seed&1 ? -1:1);            // Set up spin vector.
  4957.         }
  4958.         else
  4959.         {
  4960.             ball_inair=FALSE;
  4961.             pass_speed=end_speed+(d*(1-GRND_FRICTION));
  4962.             ballxdis=pass_speed*x/d;
  4963.             ballydis=pass_speed*y/d;
  4964.             cannot_pick_up=ball_poss;
  4965.  
  4966.             ballzdis=0;
  4967.             ballz=ball_diam/2;
  4968.             ball_xyspin=0;
  4969.             ball_zspin=0;
  4970.         }
  4971.     }
  4972.  
  4973.     holder_lose_ball();
  4974.     must_pass=FALSE;
  4975.  
  4976.     if (ps>0)
  4977.         new_interceptor(ps);
  4978. }
  4979.  
  4980. /******************************************************************************
  4981. *****************************************************************************/
  4982.  
  4983. void make_pass(match_player *player,int p,char cross=FALSE)
  4984. {
  4985.     kick_type=KT_PASS;
  4986.     float sx,sy,sz;
  4987.     cross_now=cross;
  4988.     receiver=p;
  4989.     comm_pass_type=0;
  4990.     switch(pass_type)
  4991.     {
  4992. // Player kick along ground, ball tweens to contact point and is then released...
  4993.         case(3):
  4994.             init_kick_act(&teams[ball_poss-1],MC_SIDEPASSL,MCC_SIDEPASS);
  4995.             break;
  4996.  
  4997.         case(2):
  4998.             init_kick_act(&teams[ball_poss-1],MC_DIAGBACKL,MCC_DIAGBACK);
  4999.             comm_pass_type=1;
  5000.             break;
  5001.  
  5002.         case(1):
  5003.             init_kick_act(&teams[ball_poss-1],MC_BACKHEELL,MCC_BACKHEEL);
  5004.             comm_pass_type=1;
  5005.             break;
  5006.  
  5007.         case(8):
  5008.             init_kick_act(&teams[ball_poss-1],MC_DIAGBACKR,MCC_DIAGBACK);
  5009.             comm_pass_type=1;
  5010.             break;
  5011.  
  5012.         case(7):
  5013.             init_kick_act(&teams[ball_poss-1],MC_SIDEPASSR,MCC_SIDEPASS);
  5014.             break;
  5015.  
  5016.         case(6):
  5017.             init_kick_act(&teams[ball_poss-1],MC_DIAGPASSR,MCC_DIAGPASS);
  5018.             break;
  5019.  
  5020.         case(5):
  5021.             init_kick_act(&teams[ball_poss-1],MC_PASSL,MCC_PASS);
  5022.             break;
  5023.  
  5024.         case(4):
  5025.             init_kick_act(&teams[ball_poss-1],MC_DIAGPASSL,MCC_DIAGPASS);
  5026.             break;
  5027.  
  5028.         case(-1):
  5029.             init_kick_act(&teams[ball_poss-1],MC_CHIPL,MCC_CHIP);
  5030.             comm_pass_type=2;
  5031.             break;
  5032.  
  5033.         case(16):
  5034.             init_kick_act(&teams[ball_poss-1],MC_CROSSL,MCC_CROSS);
  5035.             comm_pass_type=2;
  5036.             break;
  5037.  
  5038.         case(17):
  5039.             init_kick_act(&teams[ball_poss-1],MC_CROSSR,MCC_CROSS);
  5040.             comm_pass_type=2;
  5041.             break;
  5042. /*
  5043.         case(12):
  5044.             init_kick_act(&teams[ball_poss-1],MC_THROWL,MCC_THROWL);
  5045.             comm_pass_type=2;
  5046.             break;
  5047.  
  5048.         case(13):
  5049.             init_kick_act(&teams[ball_poss-1],MC_THROWS,MCC_THROWS);
  5050.             break;
  5051. */
  5052. // Keeper new animation start, ball in limbo until contact...
  5053.         case(11):
  5054.             init_anim(&teams[ball_poss-1],MC_HALFVOLL);
  5055. // Point at which ball leaves hand!
  5056. // Calculate current mcap offsets for given direction (newdx,newdy)!
  5057.             rotate_offs(MC_HALFVOLL,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  5058.             ballx=teams[ball_poss-1].tm_x+sx;
  5059.             bally=teams[ball_poss-1].tm_y+sy;
  5060.             ballz=teams[ball_poss-1].tm_z+sz;
  5061.             ball_limbo(teams[ball_poss-1].tm_player,MCC_HALFVOLL);
  5062.             teams[ball_poss-1].tm_limbo=1/MC_HALFVOLL_FS;
  5063.             pass_ball(receiver,FALSE);
  5064.             comm_pass_type=2;
  5065.             break;
  5066.  
  5067.         case(10):
  5068.             init_anim(&teams[ball_poss-1],MC_THROW);
  5069. // Point at which ball leaves hand!
  5070. // Calculate current mcap offsets for given direction (newdx,newdy)!
  5071.             rotate_offs(MC_THROW,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  5072.             ballx=teams[ball_poss-1].tm_x+sx;
  5073.             bally=teams[ball_poss-1].tm_y+sy;
  5074.             ballz=teams[ball_poss-1].tm_z+sz;
  5075.             ball_limbo(teams[ball_poss-1].tm_player,MCC_THROW);
  5076.             teams[ball_poss-1].tm_limbo=1/MC_THROW_FS;
  5077.             pass_ball(receiver,FALSE);
  5078.             break;
  5079.  
  5080.         case(9):
  5081.             init_anim(&teams[ball_poss-1],MC_ROLL);
  5082. // Point at which ball leaves hand!
  5083. // Calculate current mcap offsets for given direction (newdx,newdy)!
  5084.             rotate_offs(MC_ROLL,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  5085.             ballx=teams[ball_poss-1].tm_x+sx;
  5086.             bally=teams[ball_poss-1].tm_y+sy;
  5087.             ballz=teams[ball_poss-1].tm_z+sz;
  5088.             ball_limbo(teams[ball_poss-1].tm_player,MCC_ROLL);
  5089.             teams[ball_poss-1].tm_limbo=1/MC_ROLL_FS;
  5090.             pass_ball(receiver,FALSE);
  5091.             break;
  5092.  
  5093.         case(12):
  5094.             init_anim(&teams[ball_poss-1],MC_THROWS);
  5095. // Point at which ball leaves hand!
  5096. // Calculate current mcap offsets for given direction (newdx,newdy)!
  5097.             rotate_offs(MC_THROWS,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  5098.             ballx=teams[ball_poss-1].tm_x+sx;
  5099.             bally=teams[ball_poss-1].tm_y+sy;
  5100.             ballz=teams[ball_poss-1].tm_z+sz;
  5101.             ball_limbo(teams[ball_poss-1].tm_player,MCC_THROWS);
  5102.             teams[ball_poss-1].tm_limbo=1/MC_THROWS_FS;
  5103.             pass_ball(receiver,FALSE);
  5104.             break;
  5105.  
  5106.         case(13):
  5107.             init_anim(&teams[ball_poss-1],MC_THROWL);
  5108. // Point at which ball leaves hand!
  5109. // Calculate current mcap offsets for given direction (newdx,newdy)!
  5110.             rotate_offs(MC_THROWL,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  5111.             ballx=teams[ball_poss-1].tm_x+sx;
  5112.             bally=teams[ball_poss-1].tm_y+sy;
  5113.             ballz=teams[ball_poss-1].tm_z+sz;
  5114.             ball_limbo(teams[ball_poss-1].tm_player,MCC_THROWL);
  5115.             teams[ball_poss-1].tm_limbo=1/MC_THROWL_FS;
  5116.             pass_ball(receiver,FALSE);
  5117.             break;
  5118.  
  5119. // Already in appropriate animation...
  5120.         case(15):
  5121. // Header!
  5122.             fire_ball_off();
  5123.             PlayCommentaryMessage(CP_HEAD);
  5124.             break;
  5125.  
  5126.         case(14):
  5127. // Volley!
  5128.             fire_ball_off();
  5129.             break;
  5130.     }
  5131. }    
  5132.  
  5133. /******************************************************************************
  5134. *****************************************************************************/
  5135.  
  5136. void dribble_dir(match_player *player,float &xd,float &yd)
  5137. {
  5138.     float x,y,d;
  5139.     float rate=actual_spd(player);
  5140.     int i;
  5141.     char go_that_way=FALSE;
  5142.     char a=((seed<64) ? TRUE:FALSE);
  5143.  
  5144.     float sina=sin(0.174);        // approx. 10 degrees!
  5145.     float cosa=cos(0.174);
  5146.  
  5147.     float xd1=xd;
  5148.     float yd1=yd;
  5149.  
  5150.     float xd2=xd;
  5151.     float yd2=yd;
  5152.  
  5153.     float xo,yo,dif;
  5154.  
  5155.     int cnt=0;
  5156.  
  5157.     while((!go_that_way) && (drib_opps))
  5158.     {
  5159.  
  5160. // Coords of future ball.
  5161.         x=ballx+(xd*DRIB_DANGER_AREA/4);
  5162.         y=bally+(yd*DRIB_DANGER_AREA/4);
  5163.  
  5164.         go_that_way=TRUE;
  5165.  
  5166.         for (i=0; i<drib_opps; i++)
  5167.         {
  5168.             xo=x-opp_dir_tab[i][0];
  5169.             yo=y-opp_dir_tab[i][1];        // offset to future ball!
  5170.  
  5171.             d=calc_dist(xo,yo);
  5172.  
  5173.             dif=(player->tm_xdis*xo/d)+(player->tm_ydis*yo/d);
  5174.             d=d*(2-dif);
  5175.  
  5176.             if (d<DRIB_DANGER_AREA/2)
  5177.             {
  5178.                 go_that_way=FALSE;
  5179.                 break;
  5180.             }
  5181.         }
  5182.  
  5183.         if    ((x<16) || (x>pitch_len-16) || (y<16) || (y>pitch_wid-16) || (!go_that_way))
  5184.         {
  5185.             go_that_way=FALSE;
  5186.             if (a)
  5187.             {
  5188.                 xd=(xd1*cosa)-(yd1*sina);
  5189.                 yd=(yd1*cosa)+(xd1*sina);
  5190.                 xd1=xd;
  5191.                 yd1=yd;
  5192.                 a=!a;
  5193.             }
  5194.             else
  5195.             {
  5196.                 xd=(xd2*cosa)+(yd2*sina);
  5197.                 yd=(yd2*cosa)-(xd2*sina);
  5198.                 xd2=xd;
  5199.                 yd2=yd;
  5200.                 a=!a;
  5201.             }
  5202.  
  5203.             if (cnt++==36)
  5204.             {
  5205. // No-where to go, so go toward centre!
  5206.                 xd=cntspot_x-ballx;
  5207.                 yd=cntspot_y-bally;
  5208.                 d=calc_dist(xd,yd);
  5209.                 xd=xd/d;
  5210.                 yd=yd/d;
  5211.                 must_pass=TRUE;
  5212.                 break;
  5213.             }
  5214.         }
  5215.     }
  5216. }
  5217.  
  5218. /******************************************************************************
  5219. *****************************************************************************/
  5220. /*
  5221. int omake_run_a(match_player *player)
  5222. {
  5223.     if (player->tm_y>=cntspot_y)
  5224.     {
  5225. // DIR 4
  5226.         if (ballx<pitch_len-32)
  5227.         {
  5228.             if ((opp_dir_tab[3]>=0) && (opp_dir_tab[5]>=0))
  5229.             {
  5230.                 if (!opp_dir_tab[4])
  5231.                     return(4);
  5232.             }
  5233.         }
  5234.  
  5235. // DIR 5
  5236.         if ((ballx<pitch_len-32) && (bally>32))
  5237.         {
  5238.             if ((opp_dir_tab[6]>=0) && (opp_dir_tab[4]>=0))
  5239.             {
  5240.                 if (!opp_dir_tab[5])
  5241.                     return(5);
  5242.             }
  5243.         }
  5244.  
  5245. // DIR 3
  5246.         if ((bally<pitch_wid-32) && (ballx<pitch_len-32))
  5247.         {
  5248.             if ((opp_dir_tab[2]>=0) && (opp_dir_tab[4]>=0))
  5249.             {
  5250.                 if (!opp_dir_tab[3])
  5251.                     return(3);
  5252.             }
  5253.         }
  5254.  
  5255. // DIR 6
  5256.         if (bally>32)
  5257.         {
  5258.             if ((opp_dir_tab[7]>=0) && (opp_dir_tab[5]>=0))
  5259.             {
  5260.                 if (!opp_dir_tab[6])
  5261.                     return(6);
  5262.             }
  5263.         }
  5264.  
  5265. // DIR 2
  5266.         if (bally<pitch_wid-32)
  5267.         {
  5268.             if ((opp_dir_tab[3]>=0) && (opp_dir_tab[1]>=0))
  5269.             {
  5270.                 if (!opp_dir_tab[2])
  5271.                     return(2);
  5272.             }
  5273.         }
  5274.  
  5275. // DIR 7
  5276.         if ((bally>32) && (ballx>32))
  5277.         {
  5278.             if ((opp_dir_tab[0]>=0) && (opp_dir_tab[6]>=0))
  5279.             {
  5280.                 if (!opp_dir_tab[7])
  5281.                     return(7);
  5282.             }
  5283.         }
  5284.  
  5285. // DIR 1
  5286.         if ((bally<pitch_wid-32) && (ballx>32))
  5287.         {
  5288.             if ((opp_dir_tab[2]>=0) && (opp_dir_tab[5]>=0))
  5289.             {
  5290.                 if (!opp_dir_tab[1])
  5291.                     return(1);
  5292.             }
  5293.         }
  5294.  
  5295. // DIR 0
  5296.         if (ballx>32)
  5297.         {
  5298.             if ((opp_dir_tab[1]>=0) && (opp_dir_tab[7]>=0))
  5299.             {
  5300.                 if (!opp_dir_tab[0])
  5301.                     return(0);
  5302.             }
  5303.         }
  5304.     }
  5305.     else
  5306.     {
  5307. // DIR 4
  5308.         if (ballx<pitch_len-32)
  5309.         {
  5310.             if ((opp_dir_tab[3]>=0) && (opp_dir_tab[5]>=0))
  5311.             {
  5312.                 if (!opp_dir_tab[4])
  5313.                     return(4);
  5314.             }
  5315.         }
  5316.  
  5317. // DIR 3
  5318.         if ((bally<pitch_wid-32) && (ballx<pitch_len-32))
  5319.         {
  5320.             if ((opp_dir_tab[2]>=0) && (opp_dir_tab[4]>=0))
  5321.             {
  5322.                 if (!opp_dir_tab[3])
  5323.                     return(3);
  5324.             }
  5325.         }
  5326.  
  5327. // DIR 5
  5328.         if ((ballx<pitch_len-32) && (bally>32))
  5329.         {
  5330.             if ((opp_dir_tab[6]>=0) && (opp_dir_tab[4]>=0))
  5331.             {
  5332.                 if (!opp_dir_tab[5])
  5333.                     return(5);
  5334.             }
  5335.         }
  5336.  
  5337. // DIR 2
  5338.         if (bally<pitch_wid-32)
  5339.         {
  5340.             if ((opp_dir_tab[3]>=0) && (opp_dir_tab[1]>=0))
  5341.             {
  5342.                 if (!opp_dir_tab[2])
  5343.                     return(2);
  5344.             }
  5345.         }
  5346.  
  5347. // DIR 6
  5348.         if (bally>32)
  5349.         {
  5350.             if ((opp_dir_tab[7]>=0) && (opp_dir_tab[5]>=0))
  5351.             {
  5352.                 if (!opp_dir_tab[6])
  5353.                     return(6);
  5354.             }
  5355.         }
  5356.  
  5357. // DIR 1
  5358.         if ((bally<pitch_wid-32) && (ballx>32))
  5359.         {
  5360.             if ((opp_dir_tab[2]>=0) && (opp_dir_tab[5]>=0))
  5361.             {
  5362.                 if (!opp_dir_tab[1])
  5363.                     return(1);
  5364.             }
  5365.         }
  5366.  
  5367. // DIR 7
  5368.         if ((bally>32) && (ballx>32))
  5369.         {
  5370.             if ((opp_dir_tab[0]>=0) && (opp_dir_tab[6]>=0))
  5371.             {
  5372.                 if (!opp_dir_tab[7])
  5373.                     return(7);
  5374.             }
  5375.         }
  5376.  
  5377. // DIR 0
  5378.         if (ballx>32)
  5379.         {
  5380.             if ((opp_dir_tab[1]>=0) && (opp_dir_tab[7]>=0))
  5381.             {
  5382.                 if (!opp_dir_tab[0])
  5383.                     return(0);
  5384.             }
  5385.         }
  5386.     }
  5387.  
  5388. // Go to right corners...
  5389.     int y;
  5390.     int x=(pitch_len-(prat*5))-ballx;
  5391.     if (bally>cntspot_y)
  5392.         y=(pitch_wid-(prat*5))-bally;
  5393.     else
  5394.         y=((prat*5))-bally;
  5395.     return(get_dir(x,y));
  5396. }
  5397. */
  5398. /******************************************************************************
  5399. *****************************************************************************/
  5400. /*
  5401. int make_run_b(match_player *player)
  5402. {
  5403.     if (player->tm_y>=cntspot_y)
  5404.     {
  5405. // DIR 0
  5406.         if (ballx>32)
  5407.         {
  5408.             if ((opp_dir_tab[1]>=0) && (opp_dir_tab[7]>=0))
  5409.             {
  5410.                 if (!opp_dir_tab[0])
  5411.                     return(0);
  5412.             }
  5413.         }
  5414.  
  5415. // DIR 7
  5416.         if ((bally>32) && (ballx>32))
  5417.         {
  5418.             if ((opp_dir_tab[0]>=0) && (opp_dir_tab[6]>=0))
  5419.             {
  5420.                 if (!opp_dir_tab[7])
  5421.                     return(7);
  5422.             }
  5423.         }
  5424.  
  5425. // DIR 1
  5426.         if ((bally<pitch_wid-32) && (ballx>32))
  5427.         {
  5428.             if ((opp_dir_tab[2]>=0) && (opp_dir_tab[5]>=0))
  5429.             {
  5430.                 if (!opp_dir_tab[1])
  5431.                     return(1);
  5432.             }
  5433.         }
  5434.  
  5435. // DIR 6
  5436.         if (bally>32)
  5437.         {
  5438.             if ((opp_dir_tab[7]>=0) && (opp_dir_tab[5]>=0))
  5439.             {
  5440.                 if (!opp_dir_tab[6])
  5441.                     return(6);
  5442.             }
  5443.         }
  5444.  
  5445. // DIR 2
  5446.         if (bally<pitch_wid-32)
  5447.         {
  5448.             if ((opp_dir_tab[3]>=0) && (opp_dir_tab[1]>=0))
  5449.             {
  5450.                 if (!opp_dir_tab[2])
  5451.                     return(2);
  5452.             }
  5453.         }
  5454.  
  5455. // DIR 5
  5456.         if ((ballx<pitch_len-32) && (bally>32))
  5457.         {
  5458.             if ((opp_dir_tab[6]>=0) && (opp_dir_tab[4]>=0))
  5459.             {
  5460.                 if (!opp_dir_tab[5])
  5461.                     return(5);
  5462.             }
  5463.         }
  5464.  
  5465. // DIR 3
  5466.         if ((bally<pitch_wid-32) && (ballx<pitch_len-32))
  5467.         {
  5468.             if ((opp_dir_tab[2]>=0) && (opp_dir_tab[4]>=0))
  5469.             {
  5470.                 if (!opp_dir_tab[3])
  5471.                     return(3);
  5472.             }
  5473.         }
  5474.  
  5475. // DIR 4
  5476.         if (ballx<pitch_len-32)
  5477.         {
  5478.             if ((opp_dir_tab[3]>=0) && (opp_dir_tab[5]>=0))
  5479.             {
  5480.                 if (!opp_dir_tab[4])
  5481.                     return(4);
  5482.             }
  5483.         }
  5484.     }
  5485.     else
  5486.     {
  5487. // DIR 0
  5488.         if (ballx>32)
  5489.         {
  5490.             if ((opp_dir_tab[1]>=0) && (opp_dir_tab[7]>=0))
  5491.             {
  5492.                 if (!opp_dir_tab[0])
  5493.                     return(0);
  5494.             }
  5495.         }
  5496.  
  5497. // DIR 1
  5498.         if ((bally<pitch_wid-32) && (ballx>32))
  5499.         {
  5500.             if ((opp_dir_tab[2]>=0) && (opp_dir_tab[5]>=0))
  5501.             {
  5502.                 if (!opp_dir_tab[1])
  5503.                     return(1);
  5504.             }
  5505.         }
  5506.  
  5507. // DIR 7
  5508.         if ((bally>32) && (ballx>32))
  5509.         {
  5510.             if ((opp_dir_tab[0]>=0) && (opp_dir_tab[6]>=0))
  5511.             {
  5512.                 if (!opp_dir_tab[7])
  5513.                     return(7);
  5514.             }
  5515.         }
  5516.  
  5517. // DIR 2
  5518.         if (bally<pitch_wid-32)
  5519.         {
  5520.             if ((opp_dir_tab[3]>=0) && (opp_dir_tab[1]>=0))
  5521.             {
  5522.                 if (!opp_dir_tab[2])
  5523.                     return(2);
  5524.             }
  5525.         }
  5526.  
  5527. // DIR 6
  5528.         if (bally>32)
  5529.         {
  5530.             if ((opp_dir_tab[7]>=0) && (opp_dir_tab[5]>=0))
  5531.             {
  5532.                 if (!opp_dir_tab[6])
  5533.                     return(6);
  5534.             }
  5535.         }
  5536.  
  5537. // DIR 3
  5538.         if ((bally<pitch_wid-32) && (ballx<pitch_len-32))
  5539.         {
  5540.             if ((opp_dir_tab[2]>=0) && (opp_dir_tab[4]>=0))
  5541.             {
  5542.                 if (!opp_dir_tab[3])
  5543.                     return(3);
  5544.             }
  5545.         }
  5546.  
  5547. // DIR 5
  5548.         if ((ballx<pitch_len-32) && (bally>32))
  5549.         {
  5550.             if ((opp_dir_tab[6]>=0) && (opp_dir_tab[4]>=0))
  5551.             {
  5552.                 if (!opp_dir_tab[5])
  5553.                     return(5);
  5554.             }
  5555.         }
  5556.  
  5557. // DIR 4
  5558.         if (ballx<pitch_len-32)
  5559.         {
  5560.             if ((opp_dir_tab[3]>=0) && (opp_dir_tab[5]>=0))
  5561.             {
  5562.                 if (!opp_dir_tab[4])
  5563.                     return(4);
  5564.             }
  5565.         }
  5566.     }
  5567.  
  5568. // Go to left corners...
  5569.     int y;
  5570.     int x=(prat*5)-ballx;
  5571.     if (bally>cntspot_y)
  5572.         y=(pitch_wid-(prat*5))-bally;
  5573.     else
  5574.         y=((prat*5))-bally;
  5575.     return(get_dir(x,y));
  5576. }
  5577.  
  5578. */
  5579.  
  5580. /******************************************************************************
  5581. *****************************************************************************/
  5582.  
  5583. void avoid_boundary(match_player *player)
  5584. {
  5585. // Just run toward opponents goal...
  5586.     float x;
  5587.     float y=cntspot_y;
  5588.     if (player->tm_player<12)
  5589. // Goal B...
  5590.         x=pitch_len;
  5591.     else
  5592. // Goal A...
  5593.         x=0;
  5594.  
  5595.     init_run_act(player,x,y,TRUE);
  5596.     action="Dribble";
  5597. }
  5598.  
  5599. /******************************************************************************
  5600. *****************************************************************************/
  5601.  
  5602. void go_dribble(match_player *player,float x,float y)
  5603. {
  5604.     x=player->tm_x+(x*500);
  5605.     y=player->tm_y+(y*500);
  5606.  
  5607. // Make target (x,y) greater than intention range!
  5608.  
  5609.     init_run_act(player,x,y,TRUE);
  5610.     action="Dribble";
  5611. }
  5612.  
  5613. /******************************************************************************
  5614. *****************************************************************************/
  5615.  
  5616. void make_run(match_player *player)
  5617. {
  5618.     float x,y,px;
  5619.  
  5620.     if (player->tm_player<12)
  5621. // Team A
  5622.     {
  5623.         px=player->tm_x-(pitch_len-prat*10);
  5624.         if (px>0)
  5625.         {
  5626.             if (px<prat*10)
  5627.                 x=cos(px*PI/(prat*20));
  5628.             else
  5629.                 x=0;
  5630.  
  5631.             y=sqrt(1-(x*x));
  5632.  
  5633.             if (player->tm_y>cntspot_y)
  5634.                 y=-y;
  5635.  
  5636.         }
  5637.         else
  5638.         {
  5639.             x=1;
  5640.             y=0;
  5641.         }
  5642.         get_opp_dir_tab(player->tm_player);
  5643.         dribble_dir(player,x,y);
  5644.         go_dribble(player,x,y);
  5645.     }
  5646.     else            
  5647. // Team B
  5648.     {
  5649.         px=(prat*10)-player->tm_x;
  5650.         if (px>0)
  5651.         {
  5652.             if (px<prat*10)
  5653.                 x=-cos(px*PI/(prat*20));
  5654.             else
  5655.                 x=0;
  5656.  
  5657.             y=sqrt(1-(x*x));
  5658.  
  5659.             if (player->tm_y>cntspot_y)
  5660.                 y=-y;
  5661.  
  5662.         }
  5663.         else
  5664.         {
  5665.             x=-1;
  5666.             y=0;
  5667.         }
  5668.         get_opp_dir_tab(player->tm_player);
  5669.         dribble_dir(player,x,y);
  5670.         go_dribble(player,x,y);
  5671.     }
  5672.     reset_ideas(player);
  5673.     player->int_move=I_DRIBBLE;
  5674.     player->int_cnt=18-(player->tm_flair/8);
  5675.     player->go_cnt=19-(player->tm_flair/8);
  5676.     
  5677. // Where will he be at end of run!
  5678.     x=player->tm_x+(player->go_txdis*player->go_cnt);
  5679.     y=player->tm_y+(player->go_tydis*player->go_cnt);
  5680.     if (x>pitch_len || x<0 || y<0 || y>pitch_wid)
  5681.     {
  5682. // Running off pitch!!!
  5683.         avoid_boundary(player);
  5684.     }
  5685. }
  5686.  
  5687. /******************************************************************************
  5688. *****************************************************************************/
  5689.  
  5690. int run_decide(match_player *player)
  5691. {
  5692.     int opps=(player->tm_flair)-(opponents_near_holder*16);
  5693.     if (opps<=0)
  5694.         opps=MIN_RUN_PROB;
  5695.     if (seed<opps)
  5696.         return(TRUE);
  5697.     else
  5698.         return(FALSE);
  5699. }    
  5700.  
  5701. /******************************************************************************
  5702. *****************************************************************************/
  5703.  
  5704. void make_punt(match_player *player)
  5705. {
  5706.     if (ball_in_hands && (player->tm_player==KP_A || player->tm_player==KP_B))
  5707.     {
  5708.         punt_ball(player);
  5709.     }
  5710.     else
  5711.     {
  5712.         kick_type=KT_PUNT;
  5713.         pass_type=100;
  5714.         init_kick_act(player,MC_SHOOTL,MCC_SHOOT);
  5715.     }
  5716. }
  5717.  
  5718. /*****************************************************************************
  5719. *****************************************************************************/
  5720.  
  5721. void punt_ball(match_player *player)
  5722. {
  5723.     inc_pass(ball_poss);
  5724.  
  5725.     receiver_a=FALSE;
  5726.     receiver_b=FALSE;
  5727.  
  5728.     cannot_pick_up=ball_poss;
  5729.     must_punt=FALSE;
  5730.     char inh=ball_in_hands;
  5731.     ball_inair=TRUE;
  5732.     int r=rand_range(129-player->tm_ac);
  5733.  
  5734.     ballxdis=player->tm_xdis*(6+player->tm_pow/8);
  5735.     ballydis=player->tm_ydis*(6+player->tm_pow/8);
  5736.     if (heading_ball==2)
  5737.         ballzdis=4;                // Diving Header!
  5738.     else
  5739.         if (heading_ball==1)
  5740.             ballzdis=6;            // Standing or jumping header!
  5741.         else
  5742.             if (heading_ball==3)
  5743.                 ballzdis=8;
  5744.             else
  5745.             {
  5746.                 if (player->tm_player!=KP_A && player->tm_player!=KP_B)
  5747.                     ballzdis=10;        // Kick!
  5748.                 else
  5749.                     ballzdis=12;        // Kick!
  5750.             }
  5751.  
  5752.     action="Punt";
  5753.     new_shot(player->tm_player);                            // Treat as shot just in case!
  5754.  
  5755.     if (inh && (player->tm_player==KP_A || player->tm_player==KP_B))
  5756.     {
  5757.         init_anim(player,MC_KICKOUT);
  5758. // Kick out ball from hands!
  5759. // Calculate current mcap offsets for given direction (newdx,newdy)!
  5760.         float sx,sy,sz;
  5761.         rotate_offs(MC_KICKOUT,sx,sy,sz,player->tm_xdis,player->tm_ydis);
  5762.         ballx=player->tm_x+sx;
  5763.         bally=player->tm_y+sy;
  5764.         ballz=player->tm_z+sz;
  5765.         ball_limbo(player->tm_player,MCC_KICKOUT);
  5766.         player->tm_limbo=1/MC_KICKOUT_FS;
  5767.         launch_ball(1);            // Set up spin vector.
  5768.     }
  5769.     holder_lose_ball();
  5770. }
  5771.  
  5772. /******************************************************************************
  5773. *****************************************************************************/
  5774.  
  5775. int punt_decide(match_player *player)
  5776. {
  5777.     float x,y,x_factor;
  5778.     int def;
  5779.  
  5780.     x=player->tm_xdis;
  5781.     y=player->tm_ydis;
  5782.  
  5783.     if (player->tm_player>11)
  5784.     {
  5785.         if (x<0 && (ballx<pitch_len && ballx>cntspot_x) && ((seed<-(x*128)) || must_punt))
  5786.             def=ballx-cntspot_x;
  5787.         else
  5788.             return(FALSE);
  5789.     }
  5790.     else
  5791.     {
  5792.         if (x>0 && (ballx>0 && ballx<cntspot_x) && ((seed<(x*128)) || must_punt))
  5793.             def=cntspot_x-ballx;
  5794.         else
  5795.             return(FALSE);
  5796.     }
  5797.  
  5798.     if (def>(cntspot_x-(10*prat)))
  5799.         def+=128;
  5800.  
  5801. //    if (((user_player1==player->tm_player) || (user_player2==player->tm_player)) && (def>prat*20))
  5802.     if (((player->control) && (def>prat*20)) || must_punt)
  5803.         def=128*4;
  5804. // User must punt!
  5805.  
  5806.     if (def/3>seed || (first_time_it && (def*((float)player->tm_cont/64)>seed)))
  5807. // His position is defensive.
  5808.     {
  5809.         int opps=(opponents_near_holder*40)-(player->tm_flair);
  5810.         if (opps<MIN_PUNT_PROB)
  5811.             opps=MIN_PUNT_PROB;
  5812.  
  5813.         if (user_controlled)
  5814. // User must punt!
  5815.             opps=128;
  5816.  
  5817. // Facing away from goal would help...
  5818.         if (player->tm_player<12)
  5819.             x_factor=(1+x)/2;
  5820.         else
  5821.             x_factor=-(x-1)/2;
  5822.  
  5823.         if (((seed<opps*x_factor) && (x_factor>0.5)) || must_punt)
  5824.             return(TRUE);
  5825.     }
  5826.  
  5827.     return(FALSE);
  5828. }
  5829.  
  5830. /******************************************************************************
  5831. *****************************************************************************/
  5832.  
  5833. int head_punt_decide(match_player *player)
  5834. {
  5835.     float x,y;
  5836.     int def;
  5837.  
  5838.     x=player->tm_xdis;
  5839.     y=player->tm_ydis;
  5840.  
  5841.     if (player->tm_player>11)
  5842.     {
  5843.         if (x<0)
  5844.             def=ballx-cntspot_x;
  5845.         else
  5846.             return(FALSE);
  5847.     }
  5848.     else
  5849.     {
  5850.         if (x>0)
  5851.             def=cntspot_x-ballx;
  5852.         else
  5853.             return(FALSE);
  5854.     }
  5855.  
  5856.     if (def>(cntspot_x-(10*prat)))
  5857.         def+=128;
  5858.  
  5859.     if (def/4>seed)
  5860. // His position is defensive.
  5861.     {
  5862.         cannot_pick_up=-player->tm_player;
  5863.         holder_lose_ball();
  5864.         ball_inair=TRUE;
  5865.         ballxdis=(((float)(player->tm_pow))/32.0)*x+(x*6);
  5866.         ballydis=0;
  5867.         ballzdis=10;
  5868.  
  5869.         action="Punt";
  5870.         init_anim(player,MC_S_HEAD);
  5871.  
  5872.         launch_ball(1);            // Set up spin vector.
  5873.  
  5874.         play_fx(PS_HARDHEAD,ballx,bally);
  5875.  
  5876.         return(TRUE);
  5877.     }
  5878.     return(FALSE);
  5879. }
  5880.  
  5881. /******************************************************************************
  5882. *****************************************************************************/
  5883.  
  5884. float get_power()
  5885. {
  5886.     return ((float)(setp_power+16)/2);
  5887. }
  5888.  
  5889. /******************************************************************************
  5890. *****************************************************************************/
  5891.  
  5892. float get_traj()
  5893. {
  5894.     return ((float)setp_hgt/3);
  5895. }
  5896.  
  5897. /******************************************************************************
  5898. *****************************************************************************/
  5899.  
  5900. void aim_shot_at_goal(match_player *player,float &xoff,float &yoff,int rng)
  5901. {
  5902.     float x,y,d;
  5903.     float gx,gy,area;
  5904.     int side;
  5905.  
  5906.     if (player->control && pass_type==-1)
  5907.     {
  5908. // User selects direction!
  5909.         x=player->tm_xdis;
  5910.         y=player->tm_ydis;
  5911.  
  5912.         float d=calc_dist(x*128,y*128);
  5913.         xoff=(x*rng*128)/d;
  5914.         yoff=(y*rng*128)/d;
  5915.     }
  5916.     else
  5917.     {
  5918. // Auto direction select based on (accuracy)!
  5919.  
  5920.         int keeper;
  5921.         if (player->tm_player<12)
  5922.         {
  5923.             keeper=12;
  5924.             gx=pitch_len;
  5925.         }
  5926.         else
  5927.         {
  5928.             keeper=1;
  5929.             gx=0;
  5930.         }
  5931.  
  5932. // get offset to keeper (x,y)!
  5933.         x=teams[keeper-1].tm_x-ballx;
  5934.         y=teams[keeper-1].tm_y-bally;
  5935.  
  5936. // get offset to goal line through keeper (gx,gy)!
  5937.  
  5938.         gx=gx-ballx;
  5939.         gy=y*gx/x;
  5940.  
  5941.         area=gy+bally-cntspot_y;
  5942.  
  5943.         if (area>0)
  5944. // More area above keeper!
  5945.         {
  5946.             if ((player->tm_flair/2)+63>seed)
  5947. // Aim above!
  5948.             {
  5949.                 area=(cntspot_y+area)-top_post_y;
  5950.                 side=-1;
  5951.             }
  5952.             else
  5953. // Aim below!
  5954.             {
  5955.                 area=0;            // Doesn't aim for large gap!
  5956.                 side=1;
  5957.             }
  5958.         }
  5959.         else
  5960. // More area below keeper!
  5961.         {
  5962.             if ((player->tm_flair/2)+63>seed)
  5963. // Aim below!
  5964.             {
  5965.                 area=bot_post_y-(cntspot_y+area);
  5966.                 side=1;
  5967.             }
  5968.             else
  5969. // Aim above!
  5970.             {
  5971.                 area=0;            // Doesn't aim for large gap!
  5972.                 side=-1;
  5973.             }
  5974.         }
  5975.  
  5976.         xoff=gx;
  5977.  
  5978. // Calculate Accuracy offset!
  5979.         int acc_off=(seed*(8+(128-player->tm_ac)))/128;
  5980.         if (seed&4)
  5981.             acc_off=-(acc_off*rng/(20.0*prat));
  5982.         else
  5983.             acc_off=(acc_off*rng/(20.0*prat));
  5984.  
  5985. // Now. Direct at chosen target.
  5986.         if (side>0)
  5987.             yoff=bot_post_y-bally-16+acc_off;
  5988.         else
  5989.             yoff=top_post_y-bally+16+acc_off;
  5990.     }
  5991.  
  5992. // Shot Speed...
  5993.     int shot_var=seed;
  5994.     af_randomize();
  5995.     shot_var=(shot_var+seed)/2;            // Favour 64.
  5996.  
  5997.     shot_speed=6+(4*rng/(prat*60))+(9.0*(player->tm_pow+shot_var)/150);
  5998.  
  5999.     if (pass_type>0 && pass_type<5 && pass_type>5)
  6000. // Just a tap in...
  6001.         shot_speed/=2;
  6002.  
  6003.  
  6004. // Initialise swerve on ball!
  6005.     af_randomize();
  6006.     ball_zspin=0;
  6007. //    full_zspin=(float)player->tm_ac/(rng-sqrt(rng*4));
  6008.     swerve=0;
  6009.     spin_ball=0;
  6010.     max_sw_factor=0;
  6011.  
  6012. #ifdef EURO96
  6013.     if (rng>=10.0*prat && !user_controlled && !penalty_shot)
  6014. #else
  6015.     if ((rng>=10.0*prat) && (!user_controlled))
  6016. #endif
  6017.     {
  6018.         af_randomize();
  6019.         full_xyspin=(float)(seed)/128*MAX_XY_CSW*player->tm_flair/128;
  6020.         full_zspin=((float)(seed)/128*MAX_Z_CSW*player->tm_flair/128);
  6021.         spin_ball=0;
  6022.         float d=calc_dist(xoff,yoff);
  6023.         
  6024.         af_randomize();
  6025.  
  6026. // Time to reach (xoff,yoff)...
  6027.         float t=(d/shot_speed*(1-AIR_FRICTION));
  6028.           if (t>=1)
  6029.               t=0.9998;
  6030.           t=(log(1.0-t))/(log(AIR_FRICTION));    //    How long to go (d) dist!
  6031.  
  6032.         if (xoff<0)
  6033. // Going Left
  6034.         {
  6035.             if (side<0)
  6036. // Left top.
  6037.             {
  6038.                 if (xoff<yoff)
  6039.                     swerve=-1;
  6040.                 else
  6041.                     swerve=1;
  6042.             }
  6043. // Left bot.
  6044.             else
  6045.             {
  6046.                 if (xoff<yoff)
  6047.                     swerve=1;
  6048.                 else
  6049.                     swerve=-1;
  6050.             }
  6051.         }
  6052.         else
  6053. // Going Right
  6054.         {
  6055.             if (side<0)
  6056. // Right top.
  6057.             {
  6058.                 if (xoff>yoff)
  6059.                     swerve=1;
  6060.                 else
  6061.                     swerve=-1;
  6062.              }
  6063. // Right bot.
  6064.             else
  6065.             {
  6066.                 if (xoff>yoff)
  6067.                     swerve=-1;
  6068.                 else
  6069.                     swerve=1;
  6070.             }
  6071.         }
  6072. // Calculate Offset swerve angle...
  6073.         float a=0;
  6074.         for (int n=1; n<=t; n++)
  6075.         {
  6076.             a+=full_xyspin*(SW_HOLD_FACTOR/(SW_HOLD_FACTOR+n));
  6077.         }
  6078.  
  6079.         a=(a/2.2)+(d/4800);
  6080.         x=xoff/d;
  6081.         y=yoff/d;
  6082.  
  6083.         if (swerve<0)
  6084.         {
  6085.             xoff=d*((x*cos(a))-(y*sin(a)));
  6086.             yoff=d*((y*cos(a))+(x*sin(a)));
  6087.         }
  6088.         else
  6089.         {
  6090.             xoff=d*((x*cos(a))+(y*sin(a)));
  6091.             yoff=d*((y*cos(a))-(x*sin(a)));
  6092.         }
  6093.  
  6094.         ballzdis=7.2+(rng/180)+(((float)seed/64)*(128-player->tm_ac)/128)
  6095.                 +((float)(full_zspin)/2);
  6096.         spin_cnt=((ballzdis/gravity))+(ABS(full_zspin));
  6097.     }
  6098.     else
  6099.     {
  6100.         if (newk_shot)
  6101.         {
  6102.             shot_speed=get_power();
  6103.             ballzdis=get_traj();
  6104.             xoff=player->tm_xdis*10;
  6105.             yoff=player->tm_ydis*10;
  6106.             ballxdis=xoff;
  6107.             ballydis=yoff;
  6108.         }
  6109.         else
  6110.         {
  6111.             if (drive_shot)
  6112.             {
  6113.                 shot_speed+=5;
  6114.                 ballzdis=7-(shot_speed/10);
  6115.             }
  6116.             else
  6117.             {
  6118.                 if ((area>prat*6) && (rng<prat*15))
  6119. // Goal-keeper has left a large gap and attacker is close in!
  6120.                     ballzdis=1.8+(rng/180)+(((float)seed/64)*(128-player->tm_ac)/128);        // Place it low!
  6121.                 else
  6122.                     ballzdis=5.2+(rng/180)+(((float)seed/64)*(128-player->tm_ac)/128);
  6123.             }
  6124.         }
  6125.     }
  6126.  
  6127.     if (user_controlled)
  6128.     {
  6129.         if (drive_shot)
  6130.             after_touch_on=FALSE;
  6131.         else
  6132.             after_touch_on=user_controlled;
  6133.  
  6134.         full_xyspin=MAX_XY_USW*player->tm_flair/128;
  6135.         full_zspin=MAX_Z_USW*player->tm_flair/128;
  6136.         d=calc_dist(ballxdis,ballydis);
  6137.         shoot_x=ballxdis/d;
  6138.         shoot_y=ballydis/d;        // Shoot direction vectors(for after-touch).
  6139.     }
  6140.     spin_cnt=0;
  6141. }
  6142.  
  6143. /******************************************************************************
  6144. *****************************************************************************/
  6145.  
  6146. void make_shoot(match_player *player)
  6147. {
  6148.     kick_type=KT_SHOOT;
  6149.     switch(pass_type)
  6150.     {
  6151. // Straight-forward shot!
  6152.         case(-1):
  6153.             init_kick_act(player,MC_SHOOTL,MCC_SHOOT);
  6154.             break;
  6155.  
  6156. // Player kick along ground, ball tweens to contact point and is then released...
  6157.         case(3):
  6158.             init_kick_act(&teams[ball_poss-1],MC_SIDEPASSL,MCC_SIDEPASS);
  6159.             break;
  6160.  
  6161.         case(2):
  6162.             init_kick_act(&teams[ball_poss-1],MC_DIAGBACKL,MCC_DIAGBACK);
  6163.             break;
  6164.  
  6165.         case(1):
  6166.             init_kick_act(&teams[ball_poss-1],MC_BACKHEELL,MCC_BACKHEEL);
  6167.             break;
  6168.  
  6169.         case(8):
  6170.             init_kick_act(&teams[ball_poss-1],MC_DIAGBACKR,MCC_DIAGBACK);
  6171.             break;
  6172.  
  6173.         case(7):
  6174.             init_kick_act(&teams[ball_poss-1],MC_SIDEPASSR,MCC_SIDEPASS);
  6175.             break;
  6176.  
  6177.         case(6):
  6178.             init_kick_act(&teams[ball_poss-1],MC_DIAGPASSR,MCC_DIAGPASS);
  6179.             break;
  6180.  
  6181.         case(5):
  6182.             init_kick_act(&teams[ball_poss-1],MC_PASSL,MCC_PASS);
  6183.             break;
  6184.  
  6185.         case(4):
  6186.             init_kick_act(&teams[ball_poss-1],MC_DIAGPASSL,MCC_DIAGPASS);
  6187.             break;
  6188.     }
  6189. }
  6190.  
  6191. /******************************************************************************
  6192. *****************************************************************************/
  6193.  
  6194. void shoot_ball(match_player *player)
  6195. {
  6196.     receiver_a=FALSE;
  6197.     receiver_b=FALSE;
  6198.  
  6199.     if (say_names)
  6200.     {
  6201.         if (!ball_poss)
  6202.             PlayTeamSample(real_player(last_touch),2);
  6203.         else
  6204.             PlayTeamSample(real_player(ball_poss),2);
  6205.     }
  6206.  
  6207. // Fire shot!
  6208.     float goal_x;
  6209.     if (ball_poss<=11)
  6210.         goal_x=pitch_len;
  6211.     else
  6212.         goal_x=0;
  6213.     float xoff=goal_x-ballx;
  6214.     float yoff=cntspot_y-bally;
  6215.     float range=calc_dist(xoff,yoff);
  6216.     if (range<1)
  6217.         range=1;
  6218.  
  6219.     holder_lose_ball();
  6220.     ball_inair=TRUE;
  6221.     new_shot(player->tm_player);
  6222.     real_shot=TRUE;
  6223.     af_randomize();
  6224.  
  6225.     aim_shot_at_goal(player,xoff,yoff,range);
  6226.  
  6227.     if (heading_ball==2)
  6228.         ballzdis=ballzdis*.5;                // Diving Header!
  6229.     else
  6230.         if (heading_ball==3)
  6231.             ballzdis=1;
  6232.  
  6233.     if (ballzdis>0.6)
  6234.         ball_inair=TRUE;
  6235.  
  6236.     float d=calc_dist(xoff,yoff);
  6237.  
  6238.     ballxdis=shot_speed*xoff/d;
  6239.     ballydis=shot_speed*yoff/d;
  6240.  
  6241.     action="Shoot";
  6242.     cannot_pick_up=player->tm_player;
  6243.  
  6244.     drive_shot=FALSE;
  6245.     newk_shot=FALSE;
  6246.     launch_ball(0);            // Set up spin vector.
  6247.     inc_shot(player->tm_player);
  6248.     user_scorer=player->control;
  6249. }
  6250.  
  6251. /******************************************************************************
  6252. *****************************************************************************/
  6253.  
  6254. int shoot_decide(match_player *player)
  6255. {
  6256.     flag=FALSE;
  6257.     float goal_x;
  6258.     if (ball_poss<=11)
  6259.         goal_x=pitch_len;
  6260.     else
  6261.         goal_x=0;
  6262.     float xoff=goal_x-ballx;
  6263.     float yoff=cntspot_y-bally;
  6264.     int range=calc_dist(xoff,yoff);
  6265.     if (range<1)
  6266.         range=1;
  6267.  
  6268.     if (player->tm_srng)
  6269.     {
  6270.         if (user_controlled)
  6271.         {
  6272. // Big shot!
  6273.             flag=TRUE;            // in shooting range!
  6274.             pass_type=-1;
  6275.         }
  6276.         else
  6277.         {
  6278.             if (plr_facing_goal(xoff,yoff,player))
  6279.             {
  6280. // Big shot!
  6281.                 flag=TRUE;            // in shooting range!
  6282.                 pass_type=-1;
  6283.             }
  6284.             else
  6285.             {
  6286.                 pass_type=in_kicking_range(player,xoff,yoff);
  6287.                 if (user_controlled && pass_type==5)
  6288.                     pass_type=-1;
  6289.  
  6290.                 if (!pass_type)
  6291.                     flag=FALSE;
  6292.                 else
  6293.                     flag=TRUE;            // any dir shot.
  6294.             }
  6295.         }
  6296.     }
  6297.  
  6298.     if (flag)
  6299.     {
  6300. // He's in range!
  6301.  
  6302.         if ((!user_controlled) && (!must_shoot))
  6303.         {
  6304.             int opps=(10000/range)+(opponents_near_holder*(16+((128-player->tm_flair)/4)))-(16+(player->tm_flair/3));
  6305.             if (opps<MIN_SHOOT_PROB)
  6306.                 opps=MIN_SHOOT_PROB;
  6307.             if (seed>opps && !first_time_it)
  6308.                 return(FALSE);
  6309.         }
  6310.         return(TRUE);
  6311.     }
  6312.  
  6313.     if (player->tm_leave)                // He cannot touch ball again!
  6314.         must_pass=TRUE;
  6315.  
  6316.     return(FALSE);
  6317. }
  6318.  
  6319. /******************************************************************************
  6320. *****************************************************************************/
  6321.  
  6322. int head_shoot_decide(match_player *player)
  6323. {
  6324.     flag=FALSE;
  6325.     float goal_x;
  6326.  
  6327.     if (player->tm_player<=11)
  6328.         goal_x=pitch_len;
  6329.     else
  6330.         goal_x=0;
  6331.  
  6332.     float xoff=goal_x-ballx;
  6333.     float yoff=cntspot_y-bally;
  6334.     int range=calc_dist(xoff,yoff);
  6335.     if (range<1)
  6336.         range=1;
  6337.  
  6338.     if (in_header_rng)
  6339.     {
  6340. // He's in range!
  6341.  
  6342.         int opps=(5000/range)+(opponents_near_holder*32);
  6343.         if (opps<MIN_SHOOT_PROB)
  6344.             opps=MIN_SHOOT_PROB;
  6345.         if (seed>opps)
  6346.             return(FALSE);
  6347.  
  6348. // Fire shot!
  6349.         cannot_pick_up=-ball_poss;
  6350.         holder_lose_ball();
  6351.         ball_inair=TRUE;
  6352.         new_shot(player->tm_player);
  6353.         aim_shot_at_goal(player,xoff,yoff,range);
  6354.         float d=calc_dist(xoff,yoff);
  6355.          stop_ball_spin();
  6356.  
  6357.         ballzdis=ballzdis-1.4;
  6358.         ballxdis=(xoff*(12+(player->tm_pow)/4))/(d*3.4);
  6359.         ballydis=(yoff*(12+(player->tm_pow)/4))/(d*3.4);
  6360.  
  6361.         init_anim(player,MC_S_HEAD);
  6362.  
  6363.         launch_ball(0);            // Set up spin vector.
  6364.  
  6365.         play_fx(PS_HARDHEAD,ballx,bally);
  6366.         return(TRUE);
  6367.     }
  6368.     return(FALSE);
  6369. }
  6370.  
  6371. /******************************************************************************
  6372. *****************************************************************************/
  6373.  
  6374. int sort_less_than(const void *op1, const void *op2)
  6375. {
  6376.     const int p1=*(const int *)op1;
  6377.     const int p2=*(const int *)op2;
  6378.     return(p1-p2);
  6379. }
  6380.  
  6381. /******************************************************************************
  6382. *****************************************************************************/
  6383.  
  6384. int sort_greater_than(const void *op1, const void *op2)
  6385. {
  6386.     const int p1=*(const int *)op1;
  6387.     const int p2=*(const int *)op2;
  6388.     return(p2-p1);
  6389. }
  6390.  
  6391. /******************************************************************************
  6392. *****************************************************************************/
  6393.  
  6394. int sort_soonest(const void *op1, const void *op2)
  6395. {
  6396.     const short p1=*(const short *)op1;
  6397.     const short p2=*(const short *)op2;
  6398.     return(p1-p2);
  6399. }
  6400.  
  6401. /******************************************************************************
  6402. *****************************************************************************/
  6403.  
  6404. float kicking_dist(match_player *player,float x,float y,float d)
  6405. {
  6406. // Calculate back-heel distance...
  6407.     float dist=MIN_PASS_DIST+(float)player->tm_pow/3.6;
  6408.  
  6409. // Calculate difference range of 2(ahead) to 1(behind)...
  6410.     float dif=(player->tm_xdis*x/d)+(player->tm_ydis*y/d);
  6411.     float kd=dist*(2.0+dif)/2;
  6412.     return(kd);
  6413. }
  6414.  
  6415. /******************************************************************************
  6416. *****************************************************************************/
  6417.  
  6418. int in_kicking_range(match_player *player,float x,float y)
  6419. {
  6420.     float d=calc_dist(x,y);
  6421.     x=x/d;
  6422.     y=y/d;
  6423.  
  6424. // Calculate back-heel distance...
  6425.     float dist=MIN_PASS_DIST+(float)player->tm_pow/3.6;
  6426.  
  6427. // Calculate difference range of 2(ahead) to 1(behind)...
  6428.     float dif=(player->tm_xdis*x)+(player->tm_ydis*y);
  6429.     float kd=dist*(1.5+(dif/2));
  6430.  
  6431.     if (dif>KICK_AHEAD_ANG)
  6432.     {
  6433. // Straight ahead...
  6434.         if (d>dist*4)
  6435.             return(0);
  6436.         else
  6437.             if (d>dist*2)
  6438.                 return(-1);
  6439.             else
  6440.                 return(5);
  6441.     }
  6442.     else
  6443.     {
  6444. // Different dir...
  6445.         if (d>kd)
  6446.             return(FALSE);
  6447.         else
  6448.         {
  6449.             float nx=(x*player->tm_xdis)+(y*player->tm_ydis);
  6450.             float ny=(y*player->tm_xdis)-(x*player->tm_ydis);
  6451.             return(1+get_dir(nx,ny));
  6452.         }
  6453.     }
  6454. }
  6455.  
  6456. /******************************************************************************
  6457. *****************************************************************************/
  6458.  
  6459. int can_i_pass(match_player *player)
  6460. {
  6461.     int p=pass_type;
  6462.     if (p>6 && p<9)
  6463.         p=p-6;
  6464.     else
  6465.         if (p>0 && p<4)
  6466.             p=4-p;
  6467.         else
  6468.             return(pass_type);        // Forward or diagonal pass requires no special ability!
  6469.  
  6470.     if (player->tm_flair>(p*seed*0.5))
  6471.         return(pass_type);            // Skillfull enough to see move!
  6472.     else
  6473.         return(FALSE);
  6474. }
  6475.  
  6476. /******************************************************************************
  6477. *****************************************************************************/
  6478.  
  6479. int pass_decide(match_player *player,char cross=FALSE)
  6480. {
  6481.     char angle;
  6482.     int passee_tab[10][3];
  6483.     int passees=0;
  6484.     int vm;
  6485.     if ((!player->tm_act==THROW_ACT) && (ball_inair))
  6486.         vm=VISION_MULT*2/3;
  6487.     else
  6488.         vm=VISION_MULT;
  6489.  
  6490.     int x,y,d,t;
  6491.     if (player->tm_player>11)
  6492.         t=22-1;                  //team B
  6493.     else
  6494.         t=11-1;                //team A
  6495.  
  6496. /************/
  6497.  
  6498.     if (want_pass)
  6499.     {
  6500. // Try guy shouting for pass...
  6501.         int i=want_pass-1;
  6502.  
  6503.         if ((ball_poss!=KP_A && ball_poss!=KP_B)
  6504.              || !kopp_around(teams[want_pass-1].tm_x,teams[want_pass-1].tm_y,want_pass))
  6505.         {
  6506.             if ((teams[i].control)
  6507.                 || (plr_facing(teams[i].tm_x-ballx,teams[i].tm_y-bally,player))
  6508.                 || (set_piece_on && player->tm_act!=THROW_ACT))
  6509.             {
  6510.                 x=teams[i].tm_x-ballx;
  6511.                 y=teams[i].tm_y-bally;
  6512.                 d=calc_dist(x,y);
  6513.                 if ((ball_in_hands) && (d<30.0*prat))
  6514. // In throwing range!
  6515.                 {
  6516.                     passee_tab[passees][1]=i+1;
  6517.                     passee_tab[passees++][2]=pass_type;
  6518. // Add prospective passee!
  6519.                  }
  6520.                 else
  6521.                 {
  6522.                     pass_type=in_kicking_range(player,x,y);
  6523.                     pass_type=can_i_pass(player);
  6524.  
  6525.                     if ((pass_type) && (!ball_in_hands))
  6526. // Can kick that distance...
  6527.                     {
  6528.                         passee_tab[passees][1]=i+1;
  6529.                         passee_tab[passees++][2]=pass_type;
  6530. // Add prospective passee!
  6531.                     }
  6532.                     else
  6533.                     {
  6534.                         if (cross && !ball_in_hands && 
  6535.                             d<=(player->tm_vis*vm*1.4) && d>(prat*8))
  6536.                         {
  6537.                             if ((ball_poss<12 && (teams[i].tm_x)>pitch_len-(prat*18))
  6538.                                 || (ball_poss>11 && (teams[i].tm_x)<prat*18))
  6539.                             {
  6540. // In eighteen yard box!
  6541.                                 angle=cross_angle(teams[ball_poss-1].tm_xdis,
  6542.                                                     teams[ball_poss-1].tm_ydis,x,y);
  6543.             
  6544.                                 if (angle==1)
  6545. // Kicking at 90 degrees left...
  6546.                                 {
  6547.                                     pass_type=16;
  6548.                                     passee_tab[passees][1]=i+1;
  6549.                                     passee_tab[passees++][2]=pass_type;
  6550.                                 }
  6551.                                 else
  6552.                                 {
  6553.                                     if (angle==2)
  6554. // Kicking at 90 degrees right...
  6555.                                     {
  6556.                                         pass_type=17;
  6557.                                         passee_tab[passees][1]=i+1;
  6558.                                         passee_tab[passees++][2]=pass_type;
  6559.                                     }
  6560.                                 }
  6561.                             }
  6562.                         }
  6563.                     }
  6564.                 }
  6565.             }
  6566.         }
  6567.     }
  6568.  
  6569. /************/
  6570.  
  6571.     for (int i=t; i>t-11; i--)
  6572.     {
  6573.         if (player->tm_player!=i+1)
  6574. // Not man on ball!
  6575.         {
  6576.             if ((ball_poss!=KP_A && ball_poss!=KP_B)
  6577.                  || !kopp_around(teams[i].tm_x,teams[i].tm_y,i))
  6578.             {
  6579.                 if ((teams[i].tm_act<=TURN_ACT) && (teams[i].guy_on>0) && (want_pass-1!=i))
  6580. // Not Busy!
  6581.                 {
  6582.                     x=teams[i].tm_x-ballx;
  6583.                     y=teams[i].tm_y-bally;
  6584.                     d=calc_dist(x,y);
  6585.                     pass_type=in_kicking_range(player,x,y);
  6586.                     pass_type=can_i_pass(player);
  6587.  
  6588.                     if ((pass_type && !ball_in_hands) || ((ball_in_hands) && (d<20.0*prat)))
  6589. // Can kick reach him...
  6590.                     {
  6591.                         if (d<=(player->tm_vis*vm))
  6592. // In visible range!
  6593.                         {
  6594.                             if ((d/2<(MIN_PASS_DIST+(float)player->tm_pow/3.6) && !ball_in_hands) || angle_of_vis(player,x,y,teams[i].tm_dist,cross))
  6595. // Within angle of vision 90!
  6596.                             {
  6597.                                 if (!(((i==KP_A-1) || (i==KP_B-1)) && (teams[i].tm_dist<KP_MIN_PASS_DIST)))
  6598.                                 {
  6599.                                     passee_tab[passees][1]=i+1;
  6600.                                     passee_tab[passees++][2]=pass_type;
  6601.                                 }
  6602. // Add prospective passee!
  6603.                             }
  6604.                         }
  6605.                     }
  6606.                     else
  6607.                     {
  6608.                         if (cross && !ball_in_hands && 
  6609.                             d<=(player->tm_vis*vm*1.4) && d>(prat*8))
  6610.                         {
  6611.                             if ((ball_poss<12 && (teams[i].tm_x)>pitch_len-(prat*18))
  6612.                                 || (ball_poss>11 && (teams[i].tm_x)<prat*18))
  6613.                             {
  6614.                                 angle=cross_angle(teams[ball_poss-1].tm_xdis,
  6615.                                                     teams[ball_poss-1].tm_ydis,x,y);
  6616.  
  6617.                                 if (angle==1)
  6618. // Kicking at 90 degrees left...
  6619.                                 {
  6620.                                     pass_type=16;
  6621.                                     passee_tab[passees][1]=i+1;
  6622.                                     passee_tab[passees++][2]=pass_type;
  6623.                                 }
  6624.                                 else
  6625.                                 {
  6626.                                     if (angle==2)
  6627. // Kicking at 90 degrees right...
  6628.                                     {
  6629.                                         pass_type=17;
  6630.                                         passee_tab[passees][1]=i+1;
  6631.                                         passee_tab[passees++][2]=pass_type;
  6632.                                     }
  6633.                                 }
  6634.                             }
  6635.                         }
  6636.                     }
  6637.                 }
  6638.             }
  6639.         }
  6640.     }
  6641.  
  6642. //********************************//
  6643. // Passee table has been created. //
  6644. //********************************//
  6645.  
  6646. // Give preference values to each candidate...
  6647. // Low being best!
  6648.  
  6649.     int pas=0;
  6650.  
  6651.  
  6652.     if (passees)
  6653.     {
  6654.         int team_mate;
  6655.  
  6656.         if (!user_controlled)
  6657.         {
  6658. // Computer decision only...
  6659.  
  6660.             int opps;
  6661.             float tmx;
  6662.             float px=player->tm_x;
  6663.     
  6664.             for (int p=0; p<passees; p++)
  6665.             {
  6666.  
  6667.                 team_mate=passee_tab[p][1]-1;
  6668.  
  6669. // Get opponents near team-mate...
  6670.                 opps=opp_around((int)teams[team_mate].tm_x,
  6671.                                      (int)teams[team_mate].tm_y,team_mate);
  6672.  
  6673. // Passer takes this into consideration...
  6674.                 opps=64+(opps*(64+(player->tm_flair/2)));
  6675.  
  6676. // Optimum passing distance is around 10 yards...
  6677. // Anything below should start to lessen likelyhood of passing...
  6678.                 if (teams[team_mate].tm_dist<OPTIMUM_PASS)
  6679.                     opps+=(OPTIMUM_PASS-teams[team_mate].tm_dist);
  6680.     
  6681. // But, am I under threat and have to get rid of ball???
  6682.                 if (!set_piece_on && match_mode>GOAL_KICK_BR && match_mode<GOAL_KICK_TL)
  6683.                     opps-=opponents_near_holder*(32+(player->tm_flair/2));
  6684.                 else
  6685.                     opps-=64;
  6686.  
  6687. // Is he making run???
  6688.                 if (want_pass==(team_mate+1))
  6689.                     opps-=teams[team_mate].tm_flair;
  6690.     
  6691. // If in shooting range then less chance of passing...(greed factor)!
  6692.                 if (player->tm_srng)
  6693.                     opps+=GREED_FACTOR;
  6694.  
  6695.                 tmx=teams[team_mate].tm_x;
  6696.  
  6697.                 if (team_mate>11)
  6698. // Team B...
  6699.                     if (tmx>px)
  6700. // Passing back...
  6701.                         opps+=(tmx-px)*player->tm_flair/128;
  6702.                     else
  6703. // Passing forward, less difference...
  6704.                         opps+=((tmx-px)/5)*player->tm_flair/128;
  6705.                 else
  6706. // Team A...
  6707.                     if (tmx<px)
  6708. // Passing back...
  6709.                         opps+=(px-tmx)*player->tm_flair/128;
  6710.                     else
  6711. // Passing forward, less difference...
  6712.                         opps+=((px-tmx)/5)*player->tm_flair/128;
  6713.  
  6714. // The more flair less likelyhood of passing especially if opps near passee!
  6715.  
  6716.                 int op_p;
  6717.                 if (team_mate<11)
  6718.                     op_p=11;
  6719.                 else
  6720.                     op_p=0;
  6721.     
  6722. // Get vectors for pass!
  6723.                 float tx=teams[team_mate].tm_x-ballx;
  6724.                 float ty=teams[team_mate].tm_y-bally;
  6725.                 float td=teams[team_mate].tm_dist;
  6726.                 float ang=0;
  6727.                 float ox,oy,od,a;
  6728.                 tx=tx/td;
  6729.                 ty=ty/td;
  6730.  
  6731. // Any opponents in path off prospective passed ball?
  6732.  
  6733.                 for (int o=op_p; o<op_p+11; o++)
  6734.                 {
  6735.                     if ((teams[o].guy_on) && (teams[o].tm_dist<td*1.25))                // Inside pass range!
  6736.                     {
  6737.                         ox=teams[o].tm_x-ballx;
  6738.                         oy=teams[o].tm_y-bally;
  6739.                         od=teams[o].tm_dist;
  6740.                         ox=ox/od;
  6741.                         oy=oy/od;
  6742.                         a=((tx*ox)+(ty*oy));
  6743.                         if (a>0)
  6744.                         {
  6745.                             a=a*a*(96+(player->tm_flair/2))*td/od;
  6746. //                            ang+=a*(player->tm_flair/64);
  6747.                             ang+=a*(player->tm_flair/32);
  6748.                         }
  6749.                     }
  6750.                 }
  6751.     
  6752.                 if (passee_tab[p][2]==16 || passee_tab[p][2]==17)
  6753. // Crossing over opps...
  6754.                 {
  6755.                     opps+=ang/5;
  6756.                     opps=opps/4;
  6757.                 }
  6758.                 else
  6759.                     opps+=ang;
  6760.     
  6761.                 passee_tab[p][0]=opps;        // Set preference level!
  6762.     
  6763.                 af_randomize();
  6764.  
  6765. // If straight ahead pass and need to chip...
  6766.                 {
  6767.                     if (passee_tab[p][2]==5 && (ang>seed/2 || (user_controlled && chip_pass)))
  6768. // Chip over...
  6769.                          passee_tab[p][2]=-1;
  6770.     
  6771.                 }
  6772.             }
  6773.         }
  6774.         else
  6775.         {
  6776. // User preference is for distance in facing direction only...
  6777.  
  6778.             float tx,ty,dif;
  6779.             float px=player->tm_x;
  6780.             float py=player->tm_y;
  6781.             float xf=player->tm_xdis;
  6782.             float yf=player->tm_ydis;
  6783.             float min_d=2000;
  6784.             short pr=-1;
  6785.  
  6786.             for (int p=0; p<passees; p++)
  6787.             {
  6788.                  passee_tab[p][0]=100;
  6789.                 team_mate=passee_tab[p][1]-1;
  6790.  
  6791.                 tx=teams[team_mate].tm_x-px;
  6792.                 ty=teams[team_mate].tm_y-py;
  6793.  
  6794.                 if (plr_facing(tx,ty,player))
  6795.                 {
  6796. // Facing towards team-mate...
  6797.                     d=calc_dist(tx,ty);
  6798.  
  6799.                     if (d<min_d)
  6800.                     {
  6801. // Closest...
  6802.                         min_d=d;
  6803.                         pr=p;
  6804.                     }
  6805.                 }
  6806.             }
  6807.  
  6808.             if (pr>=0)
  6809.                 passee_tab[pr][0]=0;
  6810.         }
  6811.  
  6812. // Sort passee table in order of preference...
  6813.         qsort(passee_tab,passees,sizeof(int)*3,sort_less_than);
  6814.  
  6815.         if (user_controlled)
  6816.         {
  6817. // Take first team-mate on table...
  6818.             pas=passee_tab[0][1];
  6819.             pass_type=passee_tab[0][2];
  6820.         }
  6821.         else
  6822.         {
  6823. // Random selection weighted towards first in table...
  6824.  
  6825.             int chance;
  6826.  
  6827.             pas=0;
  6828.             for (int p=0; p<passees; p++)
  6829.             {
  6830.                 af_randomize();
  6831.                 chance=passee_tab[p][0];
  6832.     
  6833.                 if (chance<MAX_PASS_PROB)
  6834.                     chance=MAX_PASS_PROB;
  6835.                 else
  6836.                     if (chance>MIN_PASS_PROB)
  6837.                         chance=MIN_PASS_PROB;
  6838.     
  6839.                 if (set_piece_on)
  6840.                     chance=chance/2;
  6841.     
  6842.                 if (seed>chance)
  6843.                 {
  6844. // Choose this guy to pass to!
  6845.                     pas=passee_tab[p][1];
  6846.                     pass_type=passee_tab[p][2];
  6847.                     p=passees+1;
  6848.                 }
  6849.             }
  6850.         }
  6851.  
  6852.         if (!pas && (must_pass || user_controlled))
  6853. // Must choose!
  6854.         {
  6855.             pas=passee_tab[0][1];
  6856.             pass_type=passee_tab[0][2];
  6857.         }
  6858.     }
  6859.     else
  6860. // Absolutely no one to pass to...
  6861.     {
  6862.         if ((must_pass) || (user_controlled))
  6863.             pas=0;
  6864.     }
  6865.  
  6866.     must_pass=FALSE;
  6867.  
  6868.     if (pas>0)
  6869.     {
  6870. // He is passing to someone...
  6871.  
  6872.         d=calc_dist(teams[pas-1].tm_x-ballx,teams[pas-1].tm_y-bally);
  6873.         
  6874.         if (ball_in_hands && (player->tm_player==KP_A || player->tm_player==KP_B))
  6875.         {
  6876.             if (opp_around(teams[pas-1].tm_x,teams[pas-1].tm_y,pas))
  6877. // Don't pass it out... (opponents around!)
  6878.                 pas=0;
  6879.             else
  6880. // Keeper must throw or something...
  6881.                 if (d<prat*10)
  6882.                     pass_type=9;        // Roll it.
  6883.                 else
  6884.                     if (d<prat*20)
  6885.                         pass_type=10;        // Throw it.
  6886.                     else
  6887.                         pass_type=11;        // Halfvoll it.
  6888.         }
  6889.         else
  6890.         {
  6891.             if ((ball_in_hands) && (teams[ball_poss-1].tm_act==THROW_ACT))
  6892.             {
  6893. // Player must throw...
  6894.                 if (d<prat*15)
  6895.                     pass_type=12;        // Throw short.
  6896.                 else
  6897.                     pass_type=13;        // Throw Long.
  6898.             }
  6899.             else
  6900.             {
  6901.                 if (heading_ball)
  6902.                     pass_type=15;
  6903.             }
  6904.         }
  6905.     }
  6906.     return(pas);
  6907. }
  6908.  
  6909. /******************************************************************************
  6910. *****************************************************************************/
  6911.  
  6912. void process_comments()
  6913. {
  6914.     if (want_pass_stat!=last_touch)
  6915.     {
  6916. // His team_mate does not have ball anymore...
  6917.         if (want_pass)
  6918.         {
  6919.             teams[want_pass-1].tm_comm=0;        
  6920.             teams[want_pass-1].tm_ccnt=0;
  6921.             reset_ideas(&teams[want_pass-1]);
  6922.         }
  6923.     }
  6924. }
  6925.  
  6926. /******************************************************************************
  6927. *****************************************************************************/
  6928.  
  6929. void init_speech(int p,int comm,int t)
  6930. {
  6931.     speech_tab[p-1].say=comm;
  6932.     if (t)
  6933.         speech_tab[p-1].cnt=t;
  6934.     else
  6935.         speech_tab[p-1].cnt=SPEECH_SECS*game_speed;
  6936. }
  6937.  
  6938. /******************************************************************************
  6939. *****************************************************************************/
  6940.  
  6941. void process_speech()
  6942. {
  6943.     for (int i=1; i<players+3; i++)
  6944.     {
  6945.         if (speech_tab[i-1].cnt)
  6946.         {
  6947.             speech_tab[i-1].cnt--;
  6948.         }
  6949.     }
  6950. }
  6951.  
  6952. /******************************************************************************
  6953. *****************************************************************************/
  6954.  
  6955. void player_comment(match_player *player)
  6956. {
  6957.     if (player->tm_comm)
  6958.     {
  6959.         if ((!(--player->tm_ccnt)) || (player->tm_act>TURN_ACT))
  6960.         {
  6961.             player->tm_comm=0;
  6962.             if (want_pass==player->tm_player)
  6963.                 want_pass=0;
  6964.         }
  6965.     }
  6966. }
  6967.  
  6968. /******************************************************************************
  6969. *****************************************************************************/
  6970.  
  6971. void tackle_decide(match_player *player)
  6972. {
  6973. }
  6974.  
  6975. /******************************************************************************
  6976. *****************************************************************************/
  6977.  
  6978. void steal_decide(match_player *player)
  6979. {
  6980. }
  6981.  
  6982. /******************************************************************************
  6983. *****************************************************************************/
  6984.  
  6985. void block_decide(match_player *player)
  6986. {
  6987. }
  6988.  
  6989. /******************************************************************************
  6990. *****************************************************************************/
  6991.  
  6992. void user_free_ball(match_player *player)
  6993. {
  6994.     player->tm_stopped=FALSE;
  6995. }
  6996.  
  6997. /******************************************************************************
  6998. *****************************************************************************/
  6999.  
  7000. void other_interceptor(match_player *player)
  7001. {
  7002.     if (receiver_a==player->tm_player)
  7003.         receiver_a=FALSE;
  7004.     if (receiver_b==player->tm_player)
  7005.         receiver_b=FALSE;
  7006.  
  7007.     player->tm_notme=1+player->tm_flair/16;
  7008. }
  7009.  
  7010. /******************************************************************************
  7011. *****************************************************************************/
  7012.  
  7013. void free_ball(match_player *player)
  7014. {
  7015.     player->tm_stopped=FALSE;
  7016.     if ((!dead_ball_cnt) && (!player->tm_leave))
  7017.     {
  7018.         if (!ball_out_of_play)
  7019.         {
  7020.             if ((player->tm_player==KP_A) || (player->tm_player==KP_B))
  7021.             {
  7022. // Goal Keeper...
  7023.         
  7024.                 if ((player->tm_player==KP_A && keeper_a_in_box)
  7025.                     || (player->tm_player==KP_B && keeper_b_in_box))
  7026.  
  7027.                     if (shot_pending>0 && !shot_acknowledged && player->tm_dist<prat*50)
  7028.                     {
  7029.                         if (cannot_pick_up<=0 || ((player->tm_player<12 && cannot_pick_up>11)
  7030.                              || (player->tm_player>11 && cannot_pick_up<12)))
  7031. #ifdef EURO96
  7032. // This looks silly but leave for time being...
  7033.                             if (penalty_shot && user_controlled)
  7034.                             {
  7035.                                 if (uf1 || uf2)
  7036.                                     go_to_save_path(player);
  7037.                             }
  7038.                             else
  7039.                                 go_to_save_path(player);
  7040. #else
  7041.                              go_to_save_path(player);
  7042. #endif
  7043.  
  7044.                     }
  7045.                     else
  7046.                     {
  7047.                         if (player->tm_dist<80 && ball_inair)
  7048.                         {
  7049. // Ball is quite close...
  7050.                              go_to_save_path(player);
  7051.                         }
  7052.                     }
  7053.             }
  7054.  
  7055.             if ((!penalty_game) && (player->tm_act!=SAVE_ACT) && (player->int_move!=I_SAVE_WAIT))
  7056.             {
  7057.                 if ((thinking(player)) && (player->tm_act<=TURN_ACT))
  7058.                 {
  7059.                     if (player->tm_off)
  7060. // In offside position, must get out...
  7061.                     {
  7062.                         run_back(player);
  7063.                     }
  7064.                 }
  7065.  
  7066.                 if (!interceptor_a)
  7067.                 {
  7068.                     if (near_path_a==player->tm_player)
  7069.                     {
  7070.                         if (go_to_path(near_path_a))
  7071. //                            other_interceptor(player);
  7072. //                        else
  7073.                         {
  7074.                             if (auto_users_a && !player->control)
  7075.                             {
  7076.                                 {
  7077.                                     reselect_a();
  7078.                                     user_conts(player);
  7079.                                 }
  7080.                             }
  7081.                         }
  7082.                     }
  7083.                 }
  7084.  
  7085.                 if (!interceptor_b)
  7086.                 {
  7087.                     if (near_path_b==player->tm_player)
  7088.                     {
  7089.                         if (go_to_path(near_path_b))
  7090. //                            other_interceptor(player);
  7091. //                        else
  7092.                         {
  7093.                             if (auto_users_b && !player->control)
  7094.                             {
  7095.                                 {
  7096.                                     reselect_b();
  7097.                                     user_conts(player);
  7098.                                 }
  7099.                             }
  7100.                         }
  7101.                     }
  7102.                 }
  7103.             }
  7104.         }
  7105.     }
  7106. }
  7107.  
  7108. /******************************************************************************
  7109. *****************************************************************************/
  7110.  
  7111. void out_of_vis(match_player *player)
  7112. {
  7113. }
  7114.  
  7115. /******************************************************************************
  7116. *****************************************************************************/
  7117.  
  7118. void range_flags(match_player *player)
  7119. {
  7120.     float x=player->tm_x;
  7121.     float y=player->tm_y;
  7122.     float d;
  7123.  
  7124.     if (player->tm_player>11)
  7125. // B
  7126.     {
  7127.         d=calc_dist(x,cntspot_y-y);
  7128.     }
  7129.     else
  7130. // A
  7131.     {
  7132.         d=calc_dist(pitch_len-x,cntspot_y-y);
  7133.     }
  7134.  
  7135.     if (d<MIN_HEADER_RNG+(prat*player->tm_pow/8))
  7136.         in_header_rng=TRUE;
  7137.     else
  7138.         in_header_rng=FALSE;
  7139.  
  7140.     if (d<(MIN_SHOOT_DIST+((float)player->tm_pow*3)))
  7141.         in_shot_rng=TRUE;
  7142.     else
  7143.         in_shot_rng=FALSE;
  7144. }
  7145.                     
  7146. /******************************************************************************
  7147. *****************************************************************************/
  7148.  
  7149. // Is guy with ball in "crossing area".
  7150. // Which is a diagonal line from goal post to nearest sideline.
  7151.  
  7152. void cross_pos(match_player *player)
  7153. {
  7154.     in_cross_area=FALSE;
  7155.     if (bally>bot_post_y)
  7156.     {
  7157.         if (player->tm_player>11)
  7158.         {
  7159.             if (ballx<(bally-bot_post_y))
  7160.  
  7161. // Within diagonal from bot. left post to sideline!
  7162.             
  7163.                 in_cross_area=TRUE;
  7164.         }
  7165.         else
  7166.         {
  7167.             if ((pitch_len-ballx)<(bally-bot_post_y))
  7168.  
  7169. // Within diagonal from bot. right post to sideline!
  7170.             
  7171.                 in_cross_area=TRUE;
  7172.         }
  7173.     }
  7174.     else
  7175.     {
  7176.         if (bally<top_post_y)
  7177.         {
  7178.             if (player->tm_player>11)
  7179.             {
  7180.                 if (ballx<(top_post_y-bally))
  7181.  
  7182. // Within diagonal from top left post to sideline!
  7183.             
  7184.                     in_cross_area=TRUE;
  7185.             }
  7186.             else
  7187.             {
  7188.                 if ((pitch_len-ballx)<(top_post_y-bally))
  7189.     
  7190. // Within diagonal from top right post to sideline!
  7191.                 
  7192.                     in_cross_area=TRUE;
  7193.             }
  7194.         }
  7195.     }
  7196. }
  7197.                     
  7198. /******************************************************************************
  7199. *****************************************************************************/
  7200.  
  7201. void set_pos_flags(match_player *player)
  7202. {
  7203.     cross_pos(player);
  7204.     range_flags(player);
  7205. }
  7206.  
  7207. /******************************************************************************
  7208. *****************************************************************************/
  7209.  
  7210. void user_got_ball(match_player *player)
  7211. {
  7212.     int p=0;
  7213.     set_pos_flags(player);
  7214.  
  7215.     if (player->tm_act==STAND_ACT)
  7216.         user_spec_kick(player);
  7217.     else
  7218.     {
  7219.  
  7220.     if (uf2 && um)
  7221. // Pass in dir!
  7222.     {
  7223.         int p=(pass_decide(player,in_cross_area));
  7224.         if (pass_type==16 || pass_type==17)
  7225.             make_pass(player,p,TRUE);
  7226.         else
  7227.         {
  7228.             if (!p)
  7229.                 pass_type=5;    // Forward tap...
  7230.             spec_kick_type=SPACT_FPASS;
  7231.             setp_kick_x=player->tm_xdis;
  7232.             setp_kick_y=player->tm_ydis;
  7233.             make_pass(player,p,FALSE);
  7234.         }
  7235.     }
  7236.     else
  7237.     {
  7238.         if (uf1 && um)
  7239. // Try shooting...
  7240.         {
  7241.             if (shoot_decide(player))
  7242.                 make_shoot(player);
  7243.             else
  7244. // Try punt...
  7245.             {
  7246.                 if (punt_decide(player))
  7247.                     make_punt(player);
  7248.                 else
  7249. // Try high pass to head...
  7250.                 {
  7251.                     chip_pass=TRUE;
  7252.                     int p=(pass_decide(player,FALSE));
  7253.                     if (p && (pass_type==16 || pass_type==17 || pass_type==-1))
  7254.                         make_pass(player,p,TRUE);
  7255.                     else
  7256.                     {
  7257.                         p=0;
  7258.                         chip_pass=FALSE;
  7259.                         pass_type=-1;    // Forward tap...
  7260.                         spec_kick_type=SPACT_FPASS;
  7261.                         setp_kick_x=player->tm_xdis;
  7262.                         setp_kick_y=player->tm_ydis;
  7263.                         make_pass(player,p,FALSE);
  7264.                     }
  7265.                 }
  7266.             }
  7267.         }
  7268.     }
  7269.  
  7270.     }
  7271.  
  7272. /*
  7273.         else
  7274.         {
  7275.             if (must_punt)
  7276.                 if (punt_decide(player))
  7277.                     make_punt(player);
  7278.             else
  7279.             {
  7280.                 if (uf1)
  7281.                 {
  7282. // He has pressed front fire button (1)!
  7283. // PUNT!
  7284.                     if (punt_decide(player))
  7285.                         make_punt(player);
  7286.                     else
  7287.                     {
  7288. // SHOOT!
  7289.                         if (player->tm_srng)
  7290.                         {
  7291.                             shoot_decide(player);
  7292.                             make_shoot(player);
  7293.                         }
  7294.                         else
  7295.                         {
  7296.                             must_pass=TRUE;
  7297.                             chip_pass=TRUE;
  7298.                             int p=pass_decide(player,FALSE);
  7299.                             make_pass(player,p,FALSE);
  7300.                         }
  7301.                     }
  7302.                 }
  7303.                 else
  7304.                 {
  7305.                     if (uf2)
  7306.                     {
  7307. // He has pressed top fire button (2)!
  7308.                         must_pass=TRUE;
  7309. // CROSS!
  7310.                         if (in_cross_area)
  7311.                         {
  7312.                             p=(pass_decide(player,TRUE));
  7313.                             if (p)
  7314.                                 make_pass(player,p,TRUE);
  7315.                         }
  7316.                         if (!p)
  7317.                         {
  7318. // PASS!
  7319.                             p=(pass_decide(player,FALSE));
  7320.                             if (p)
  7321.                                 make_pass(player,p,FALSE);
  7322.                         }
  7323.                     }
  7324.                 }
  7325.             }
  7326.         }
  7327.     }
  7328. */
  7329.  
  7330.     set_piece_on=FALSE;
  7331. }
  7332.  
  7333. /******************************************************************************
  7334. *****************************************************************************/
  7335.  
  7336. void got_ball(match_player *player)
  7337. {
  7338.     int p=0;
  7339.  
  7340.     if ((player->tm_player==KP_A) || (player->tm_player==KP_B))
  7341.     {
  7342.  
  7343. /****************
  7344. ** Goal-Keeper    **        
  7345. ****************/
  7346.  
  7347. // PUNT!
  7348.         if (punt_decide(player))
  7349.             make_punt(player);
  7350.         else
  7351.         {
  7352. // PASS!
  7353.             int p=(pass_decide(player));
  7354.             if (p)
  7355.                 make_pass(player,p);
  7356.             else
  7357.             {
  7358.                 if ((player->tm_player==KP_A && keeper_a_in_box)
  7359.                     || (player->tm_player==KP_B && keeper_b_in_box))
  7360.                 {
  7361. // Can pick ball up...
  7362.  
  7363.                     if (!ball_in_hands)
  7364.                     {
  7365.                         if ((cannot_pick_up<=0)
  7366.                             || (cannot_pick_up<12 && ball_poss>11 && keeper_b_in_box)
  7367.                             || (cannot_pick_up>11 && ball_poss<12 && keeper_a_in_box))
  7368.  
  7369.                         {
  7370.                             if (opp_around(ballx,bally,player->tm_player))
  7371.                             {
  7372.                                 holder_lose_ball();
  7373.                                 keep_dive=TRUE;
  7374.                                 go_to_save_path(player,TRUE);
  7375.                             }
  7376.                             else
  7377.                                 init_pickup_act(player);
  7378.                         }
  7379.                         else
  7380.                         {
  7381.                             if (player->tm_poss)
  7382.                                 must_punt=TRUE;
  7383.                             if (punt_decide(player))
  7384.                                 make_punt(player);
  7385.                             else
  7386. // RUN!
  7387.                                   make_run(player);
  7388.                         }
  7389.                     }
  7390.                 }
  7391.                 else
  7392.                 {
  7393. // Can't touch ball with hands...
  7394.                     must_punt=TRUE;
  7395.                 }
  7396.             }
  7397.         }
  7398.     }
  7399.  
  7400.     else
  7401.     {
  7402.  
  7403. /***********
  7404. ** PLAYER **        
  7405. ***********/
  7406.  
  7407. // Not taking throw!
  7408.  
  7409.         set_pos_flags(player);
  7410. // SHOOT!
  7411.         if (shoot_decide(player))
  7412.             make_shoot(player);
  7413.         else
  7414.         {
  7415. // CROSS!
  7416.             if (in_cross_area)
  7417.             {
  7418.                 p=(pass_decide(player,TRUE));
  7419.                 if (p)
  7420.                     if (pass_type==16 || pass_type==17)
  7421.                         make_pass(player,p,TRUE);
  7422.                     else
  7423.                         make_pass(player,p,FALSE);
  7424.             }
  7425.             if (!p)
  7426.             {
  7427. // PASS!
  7428.                 p=(pass_decide(player));
  7429.                 if (p)
  7430.                     make_pass(player,p);
  7431.                 else
  7432.                 {
  7433. // PUNT!
  7434.                     if (punt_decide(player))
  7435.                         make_punt(player);
  7436.                     else
  7437.                     {
  7438. // RUN!
  7439.                           make_run(player);
  7440.                     }
  7441.                 }
  7442.             }
  7443.         }
  7444.     }
  7445.     set_piece_on=FALSE;
  7446.  
  7447. }
  7448.  
  7449. /******************************************************************************
  7450. *****************************************************************************/
  7451.  
  7452. int help_chance(match_player *player)
  7453. {
  7454.     int f=64+(player->tm_flair/2);
  7455.     float r,xd;
  7456.  
  7457. // Less calculated range if pass is to be made up-field...
  7458.     if (player->tm_player>11)
  7459. // Team B...
  7460.     {
  7461.         xd=player->tm_x-ballx;
  7462.         if (xd>0)
  7463.             xd=xd*2;
  7464.     }
  7465.     else
  7466. // Team A...
  7467.     {
  7468.         xd=player->tm_x-ballx;
  7469.         if (xd<0)
  7470.             xd=xd*2;
  7471.     }
  7472.  
  7473.     r=calc_dist(xd,bally-player->tm_y)/(prat*2);
  7474.     int help;
  7475.  
  7476.     if (support_me)
  7477.         help=512-(r*r);
  7478.     else
  7479.         help=32+(opponents_near_holder*80*f/128)
  7480.                     -(opp_around(player->tm_x,player->tm_y,player->tm_player)*64*f/128)
  7481.                     -(r*r);
  7482.  
  7483. // Dead ball situation...
  7484.  
  7485.     return(help);
  7486. }
  7487.  
  7488. /******************************************************************************
  7489. *****************************************************************************/
  7490.  
  7491. void we_have_ball(match_player *player)
  7492. {
  7493.     if (player->tm_player!=KP_A && player->tm_player!=KP_B && !player->tm_stopped
  7494.          && match_mode!=PEN_KICK_A && match_mode!=PEN_KICK_B)
  7495.     {
  7496.         if ((thinking(player)) && (player->tm_act<=TURN_ACT))
  7497.         {
  7498.             if (player->tm_off)
  7499. // In offside position, must get out...
  7500.             {
  7501.                 run_back(player);
  7502.             }
  7503.             else
  7504.             {
  7505.                 if (!want_pass)
  7506.                 {
  7507.                     int help=help_chance(player);
  7508.                     if (help<MIN_HELP_CHANCE)
  7509.                         help=MIN_HELP_CHANCE;
  7510.                     if (seed<=help)
  7511. // Ask for Pass!
  7512.                     {
  7513.                         if (player->tm_dist<CALL_DIST)
  7514. //                if (angle_of_vis(player,ballx-player->tm_x,bally-player->tm_y,player->tm_dist,FALSE))
  7515.                         {
  7516.                             want_pass=player->tm_player;
  7517.                             want_pass_stat=ball_poss;
  7518.                             player->tm_ccnt=40;
  7519.                             player->tm_comm=-SAY_PASS;
  7520.                             reset_ideas(player);
  7521.                             player->int_move=I_RUN_ON;
  7522.                             player->int_cnt=40;
  7523.  
  7524.                             if (in_cross_area)
  7525.                             {
  7526.                                 float x=player->tm_x;
  7527.                                 float y=player->tm_y;
  7528.                                 int i=player->tm_player;
  7529.  
  7530.                                 if ((i<12) && (x>(pitch_len-(prat*15))) && (y>(cntspot_y-(prat*18)))
  7531.                                     && (y<(cntspot_y+(prat*18)))
  7532.                                     && (teams[i].tm_dist>(prat*20)))
  7533.  
  7534.                                     player->tm_comm=-SAY_CROSS;
  7535.  
  7536.                                 if ((i>11) && (x<(prat*15)) && (y>(cntspot_y-(prat*18)))
  7537.                                     && (y<(cntspot_y+(prat*18)))
  7538.                                     && (teams[i].tm_dist>(prat*20)))
  7539.  
  7540.                                     player->tm_comm=-SAY_CROSS;
  7541.                             }
  7542. // Run towards opponents penalty spot...
  7543.                             float x,y,d;
  7544.                             if (player->tm_player<12)
  7545.                                 x=pitch_len-ballx;
  7546.                             else
  7547.                                 x=-ballx;
  7548.  
  7549.                             y=cntspot_y-bally;
  7550.                     
  7551.                             d=calc_dist(x,y);
  7552.  
  7553. // How far is half way to goal...
  7554.  
  7555.                             float kd=kicking_dist(&teams[ball_poss-1],x,y,d)-(prat*2);
  7556.                             if (d/2<kd)
  7557.                                 init_run_act(player,ballx+x/2,bally+y/2,FALSE);
  7558.                             else
  7559.                                 init_run_act(player,ballx+(x/d*kd),bally+(y/d*kd),FALSE);
  7560.                             player->int_cnt=player->go_cnt;
  7561.                             player->tm_ccnt=player->go_cnt;
  7562.                         }
  7563.                         else
  7564.                         {
  7565.                             if (!support_me)
  7566.                             {
  7567.                                  player->tm_ccnt=40;
  7568.                                 player->tm_comm=-SAY_GIVE;
  7569.                             }
  7570.                         }
  7571.                     }
  7572.                 }
  7573.             }
  7574.         }
  7575.     }
  7576. }
  7577.  
  7578. /******************************************************************************
  7579. *****************************************************************************/
  7580.  
  7581. int in_close(match_player *player)
  7582. {
  7583.     if (player->tm_dist<DRIB_DANGER_AREA)
  7584.         return(TRUE);
  7585.     else
  7586.         return(FALSE);
  7587. }
  7588.  
  7589. /*****************************************************************************
  7590. *****************************************************************************/
  7591.  
  7592. int can_close_down(match_player *player)
  7593. {
  7594.     int p=player->tm_player;
  7595.     if ((nearest_a==p) || (nearest_b==p))
  7596.         return(TRUE);
  7597.     else
  7598.         return(FALSE);
  7599. }
  7600.  
  7601. /*****************************************************************************
  7602. *****************************************************************************/
  7603.  
  7604. void close_him_down(match_player *player)
  7605. {
  7606.     player->int_move=I_CLOSE_DOWN;
  7607.     player->int_cnt=(player->tm_flair/4);
  7608.     if (!go_to_path(player->tm_player))
  7609.         other_interceptor(player);
  7610.     action="Close Down";
  7611. }    
  7612.  
  7613. /*****************************************************************************
  7614. *****************************************************************************/
  7615.  
  7616. void force_error(match_player *player)
  7617. {
  7618.     if ((player->tm_player<12 && !auto_users_a) 
  7619.         || (player->tm_player>11 && !auto_users_b))
  7620.     {
  7621. // No team users so computer must control this guy...
  7622.  
  7623.         if (player->tm_dist<STEAL_DIST || teams[ball_poss-1].tm_act==TACKLE_ACT)
  7624.         {
  7625.             if (!go_to_path(player->tm_player))
  7626.                 other_interceptor(player);
  7627. //            else
  7628. //                player->int_move=I_STEAL;
  7629.         }
  7630.         else
  7631.         {
  7632.             int chance=32;
  7633.             if (player->tm_player<12)
  7634.  
  7635. // The further up the park, the more chance of direct tackling!
  7636.  
  7637.                 chance-=((pitch_len-player->tm_x)/48);
  7638.             else
  7639.                 chance-=(player->tm_x/48);
  7640.  
  7641.             if (chance<=seed && teams[ball_poss-1].tm_act!=TACKLE_ACT
  7642.                  && teams[ball_poss-1].int_move!=I_GET_UP)
  7643.                 get_tack_path(player);
  7644.             else
  7645.                 go_to_between(player->tm_player);    // get yourself between him and goal!
  7646.         }
  7647.     }
  7648. }
  7649.  
  7650. /*****************************************************************************
  7651. *****************************************************************************/
  7652.  
  7653. void forceful_retrieve(match_player *player)
  7654. {
  7655.     if ((player->tm_player<12 && !auto_users_a) 
  7656.         || (player->tm_player>11 && !auto_users_b))
  7657.     {
  7658. // No team users so computer must control this guy...
  7659.         get_tack_path(player);
  7660.     }
  7661. }
  7662.  
  7663. /******************************************************************************
  7664. *****************************************************************************/
  7665.  
  7666. void go_to_side(match_player *player)
  7667.  
  7668. // Send player to the side off opponent with ball...
  7669.  
  7670. {
  7671. // His intention is to intercept ball.
  7672. // Therefore his flair determines no. of turns before rethink!
  7673.  
  7674.     int ff=33-(player->tm_flair/4);
  7675.     player->int_move=I_INTERCEPT;        // Intercept ball!
  7676.     player->int_cnt=ff;                        // Flair factor.
  7677.  
  7678.     float dx=teams[ball_poss-1].tm_xdis;
  7679.     float dy=teams[ball_poss-1].tm_ydis;
  7680.  
  7681.     float x=(ballx-player->tm_x)/player->tm_dist;            // vector to ball...
  7682.     float y=(bally-player->tm_y)/player->tm_dist;
  7683.  
  7684. // Which side to go to...???
  7685.     if ((x*dy)>(y*dx))
  7686.     {
  7687.         x=-dy;        // 90 degrees clockwise...
  7688.         y=dx;
  7689.     }
  7690.     else
  7691.     {
  7692.         x=dy;        // 90 degrees anti-clockwise...
  7693.         y=-dx;
  7694.     }
  7695.  
  7696.     x=ballx+(x*prat);
  7697.     y=bally+(y*prat);
  7698.  
  7699.     init_run_act(player,x,y,TRUE);                //Go to path point!
  7700. }
  7701.  
  7702. /******************************************************************************
  7703. *****************************************************************************/
  7704.  
  7705. void go_to_between(int p_num)
  7706.  
  7707. // Send player(p_num) to intersection point between ball path and goal centre.
  7708. // If he cannot meet ball then best try!
  7709.  
  7710. {
  7711.     int x,y,z,d;
  7712.     float px=teams[p_num-1].tm_x;
  7713.     float py=teams[p_num-1].tm_y;
  7714.     float goal_x;
  7715.     int rate=actual_spd(&teams[p_num-1]);
  7716.  
  7717.     action="Between";
  7718.  
  7719.     if (p_num<12)
  7720.         goal_x=0;
  7721.     else
  7722.         goal_x=pitch_len;
  7723.  
  7724. // His intention is to intercept ball.
  7725. // Therefore his flair determines no. of turns before rethink!
  7726.  
  7727.     int ff=33-(teams[p_num-1].tm_flair/4);
  7728.     teams[p_num-1].int_move=I_INTERCEPT;        // Intercept ball!
  7729.     teams[p_num-1].int_cnt=ff;                        // Flair factor.
  7730.  
  7731.     for (int i=1; i<50; i++)
  7732.     {
  7733.         x=ball_pred_tab[i][0];
  7734.         y=ball_pred_tab[i][1];
  7735.         z=ball_pred_tab[i][2];
  7736.         d=calc_dist(goal_x-x,cntspot_y-y);
  7737.         if (d<1)
  7738.             d=1;
  7739.         
  7740.         x=x+(((goal_x-x)*BETWEEN_DIST)/d);
  7741.         y=y+(((cntspot_y-y)*BETWEEN_DIST)/d);
  7742.  
  7743.         if (z<=PLAYER_HEIGHT)
  7744.         {
  7745.             d=calc_dist(x-px,y-py);
  7746. //            d=(int)(((float)d)/rate);                    //How many steps?
  7747.             d=get_there_time(p_num,x,y);                    //How many steps?
  7748.             if (d<=i)
  7749. // He can get there in time!
  7750.             {
  7751.                 init_run_act(&teams[p_num-1],x,y,TRUE);                //Go to path point!
  7752.                 i=60;                                                // End For Loop!
  7753.             }
  7754.         }
  7755.     }
  7756.     if (i<60)
  7757. // He cant intersect!
  7758.         init_run_act(&teams[p_num-1],x,y,FALSE);            // run toward last.
  7759. }
  7760.  
  7761. /******************************************************************************
  7762. *****************************************************************************/
  7763.  
  7764. void user_opp_has_ball(match_player *player)
  7765. {
  7766.     if (uf1)
  7767. // Tackle opp.
  7768.     {
  7769.         user_init_tackle(player);
  7770.     }
  7771.     else
  7772.     {
  7773.         if (uf2)
  7774. // Steal from opp.
  7775.         {
  7776.             if (player->tm_dist<(STEAL_DIST/4))
  7777.             {
  7778.                 init_steal_act(player);
  7779.             }
  7780. #ifdef EURO96
  7781.             else
  7782. // Burst_of_speed...
  7783.             {
  7784.                 if (!burst_timer[user_controlled-1]--)
  7785.                     burst_timer[user_controlled-1]=REAL_SPEED;
  7786.                 else
  7787.                     if (!burst_timer[user_controlled-1])
  7788.                         burst_timer[user_controlled-1]=-1;
  7789.             }
  7790. #endif
  7791.         }
  7792.         else
  7793.              burst_timer[user_controlled-1]=0;
  7794.     }
  7795. }
  7796.  
  7797. /******************************************************************************
  7798. *****************************************************************************/
  7799.  
  7800. void opp_has_ball(match_player *player)
  7801. {
  7802.     if ((player->tm_player==KP_A) || (player->tm_player==KP_B))
  7803.     {
  7804.  
  7805. /****************
  7806. ** Goal-Keeper    **        
  7807. ****************/
  7808.  
  7809.         if (player->tm_player<12)
  7810. // KP_A...
  7811.         {
  7812.             if ((keeper_a_in_box) && (player->tm_dist<DIVE_FEET_DIST) && (seed>player->tm_flair))
  7813. // Can dive for ball...
  7814.             {
  7815.                 keep_dive=TRUE;
  7816.                 go_to_save_path(player,TRUE);
  7817.             }
  7818.         }
  7819.         else
  7820. // KP_B...
  7821.         {
  7822.             if ((keeper_b_in_box) && (player->tm_dist<DIVE_FEET_DIST) && (seed>player->tm_flair))
  7823. // Can dive for ball...
  7824.             {
  7825.                 keep_dive=TRUE;
  7826.                 go_to_save_path(player,TRUE);
  7827.             }
  7828.         }
  7829.     }
  7830.  
  7831.     {
  7832.  
  7833. /***********
  7834. ** PLAYER **        
  7835. ***********/
  7836.  
  7837.          if ((ball_in_hands) || (ball_out_of_play))
  7838. // Don't tackle keeper directly!
  7839.         {
  7840.  
  7841.         }
  7842.         else
  7843.         {
  7844.             if ((player->tm_pos) && (player->tm_pos<=close_in_number)
  7845.                 && ((player->tm_player!=KP_A) && (player->tm_player!=KP_B))
  7846.                 || (player->tm_pos==1))
  7847.             {                
  7848. // There's not too many guys going for opponent with ball!
  7849.  
  7850.                 if (in_close(player))
  7851. // I am close enough to hassle!
  7852.                 {
  7853.                     short d=get_facing_opp_dir(player);
  7854.  
  7855.                     if (d==-1)
  7856.                     {
  7857. // He has his back to me!
  7858.                          if ((ball_speed<1) && ((seed&4)
  7859.                              || (player->tm_player>11 && ballx<cntspot_x)
  7860.                              || (player->tm_player<12 && ballx>cntspot_x)))
  7861.  
  7862. // Try and go round a bit...
  7863.                             go_to_side(player);
  7864.                         else
  7865.                             if ((teams[ball_poss-1].tm_act==TACKLE_ACT && teams[ball_poss-1].go_cnt>EFFECTIVE_TACK)
  7866.                                  || teams[ball_poss-1].int_move==I_GET_UP)
  7867.                                 force_error(player);
  7868.                             else
  7869.                                 go_to_between(player->tm_player);    // get yourself between him and goal! 
  7870.                     }
  7871.                     else
  7872.  
  7873. // He is not shielding ball!
  7874.                     {
  7875.                         if (d==1)
  7876.                         {
  7877. // He has his side to me!
  7878.                             if    (seed&8 && (teams[ball_poss-1].tm_act==TACKLE_ACT || teams[ball_poss-1].int_move==I_GET_UP))
  7879. // Opponent is not able to turn and avoid... (So go directly to ball!)
  7880.                                 force_error(player);
  7881.                             else
  7882.                                 if ((player->tm_player!=KP_A) && (player->tm_player!=KP_B))
  7883. // Not the keeper!
  7884.                                     forceful_retrieve(player);    // Tackle directly!
  7885.                                 else
  7886.                                     force_error(player);
  7887.                         }
  7888.                         else
  7889.  
  7890. // He is facing towards me!
  7891.                             force_error(player);            // More patient style of attack!
  7892.                     }
  7893.                 }
  7894.                 else
  7895. // Not in close enough!
  7896.                 {
  7897.                     if (can_close_down(player))
  7898.  
  7899. // I can close him down!
  7900.                         close_him_down(player);
  7901.                 }
  7902.             }
  7903.         }    
  7904.     }
  7905. }
  7906.  
  7907. /******************************************************************************
  7908. *****************************************************************************/
  7909.  
  7910. void user_intelligence(match_player *player)
  7911. {
  7912.     if (match_mode || !ball_poss)
  7913.         intelligence(player);
  7914.     else
  7915.     {
  7916.         char busy=0;
  7917.         if (player->int_cnt)                //Is he busy?
  7918.         {
  7919.             if (--(player->int_cnt))
  7920.                 busy=1;
  7921.                 else
  7922.             {
  7923.                 player->int_cnt=-1;
  7924.                 reset_ideas(player);
  7925.             }
  7926.         }
  7927.  
  7928.         if (player->tm_act<=TURN_ACT)    // Player is standing or running or turning!
  7929.         {
  7930.             if (!busy)
  7931.             {
  7932.                 if (!ball_poss)
  7933.                     user_free_ball(player);
  7934.                 else
  7935.                 {
  7936.                     if (ball_poss==player->tm_player)
  7937.                         user_got_ball(player);
  7938.                     else
  7939.                     {
  7940.                         if (((ball_poss<12) && (player->tm_player>11))
  7941.                             || ((ball_poss>11) && (player->tm_player<12)))
  7942.                             user_opp_has_ball(player);
  7943.                     }
  7944.                 }
  7945.             }
  7946.         }
  7947.     }
  7948. }
  7949.  
  7950. /******************************************************************************
  7951. *****************************************************************************/
  7952.  
  7953. void offside_rule(match_player *player)
  7954. {
  7955.     if (player->tm_player<12)
  7956. // Team A...
  7957.     {
  7958.  
  7959.         if ((!match_mode) && (!ball_poss && ball_released>0) && (last_touch<12)
  7960.              && (last_touch!=player->tm_player) && (player->tm_off) && (!just_scored)
  7961.              && (ballx<player->tm_x))
  7962. //             && (ballx<player->tm_x) && receiver_a==player->tm_player)
  7963. // His team-mate has released ball and he is in an offside pos...
  7964.  
  7965.             init_offside(player);    // Does Linesman see it!
  7966.         else
  7967.             if ((ball_poss<12) && (player->tm_x>cntspot_x)
  7968.                  && (can_be_offside) && (player->tm_x>(defense_b+prat)) &&  (!just_scored))
  7969. // Player is in opponents half, his opponent doesn't have ball and
  7970. // in normal play, and no defenders behind.
  7971.             {
  7972.                 if (!player->tm_off)    
  7973.                     player->tm_off=-1;        // Potential Offside (get back).
  7974.             }
  7975.             else
  7976.                 player->tm_off=FALSE;    // Not offside.
  7977.     }
  7978.     else
  7979. // Team B...
  7980.     {
  7981.         if ((!match_mode) && (!ball_poss && ball_released<0) && (last_touch>11)
  7982.              && (last_touch!=player->tm_player) && (player->tm_off) && (!just_scored)
  7983.              && (ballx>=player->tm_x))
  7984. //             && (ballx>=player->tm_x) && receiver_b==player->tm_player)
  7985. // His team-mate has released ball and he is in an offside pos...
  7986.  
  7987.             init_offside(player);    // Does Linesman see it!
  7988.         else
  7989.             if ((ball_poss>11 || !ball_poss) && (player->tm_x<cntspot_x)
  7990.                  && (can_be_offside) && (player->tm_x<(defense_a-prat)) && (!just_scored))
  7991. // Player is in opponents half, his team mate has the ball
  7992. // in normal play, and no defenders behind.
  7993.  
  7994.             {
  7995.                 if (!player->tm_off)    
  7996.                     player->tm_off=-1;        // Potential Offside (get back).
  7997.             }
  7998.             else
  7999.                 player->tm_off=FALSE;    // Not offside.
  8000.  
  8001.     }
  8002.  
  8003.     if ((player->tm_off==TRUE) && (!match_mode) && (!just_scored))
  8004. // Linesman has indicated offside...
  8005.     {
  8006. // Is he interfering with play...
  8007.         if (player->tm_dist<ref_strictness*1.1)
  8008.         {
  8009.             offside_now=TRUE;
  8010.             init_foul(player->tm_player,FALSE,TRUE);    // Indirect F.K. for offside!
  8011.             player->tm_off=FALSE;
  8012.         }
  8013.     }
  8014. }
  8015.  
  8016. /******************************************************************************
  8017. *****************************************************************************/
  8018.  
  8019. void override(match_player *player)
  8020. {
  8021.     if (offside_on)
  8022.         offside_rule(player);
  8023. }
  8024.  
  8025. /******************************************************************************
  8026. *****************************************************************************/
  8027.  
  8028. void remove_player(match_player *player)
  8029. {
  8030.     player->guy_on=FALSE;
  8031.     if (!player_being_subbed)
  8032.     {
  8033.         hold_up_play=4*REAL_SPEED;
  8034.         camera=sub_camera;
  8035.         player_on_off=FALSE;
  8036.         ref_wait=(160-ref_strictness)*REAL_SPEED/8;
  8037.     }
  8038. }
  8039.  
  8040. /******************************************************************************
  8041. *****************************************************************************/
  8042.  
  8043. void init_off_int(match_player *player)
  8044. {
  8045.     allow_replay=FALSE;
  8046.     float tx=stadlist[setup.stadium].tunlx;
  8047.     float ty=-stadlist[setup.stadium].tunlz;
  8048.     float tly;
  8049.     if (ty>cntspot_y)
  8050.         ty+=60;
  8051.     else
  8052.         ty-=60;
  8053.  
  8054.     if (player_on_off>0 && calc_dist(tx-player->tm_x,ty-player->tm_y)<prat*2)
  8055.     {
  8056. // In tunnel! (get off)!
  8057.         remove_player(player);
  8058.         player->tm_trap=0;
  8059.     }
  8060.     else
  8061.     {
  8062.         player->draw_me=TRUE;
  8063.         player->int_cnt=600;
  8064.         player->int_move=I_OFF;
  8065.  
  8066.         if (ty>cntspot_y)
  8067.             tly=pitch_wid;
  8068.         else
  8069.             tly=0;
  8070.  
  8071.         if (player->tm_trap || calc_dist(tx-player->tm_x,tly-player->tm_y)<prat*2)
  8072. // At touch-line...(send him into tunnel)!
  8073.         {
  8074.             if (player_on_off<0)
  8075.             {
  8076. // Coming on...
  8077.                 player->int_move=0;
  8078.                 reset_ideas(player);
  8079.                 player_on_off=FALSE;
  8080.                 camera=sub_camera;
  8081.                 allow_replay=TRUE;
  8082.             }
  8083.             else
  8084.             {
  8085.                 player->tm_trap=TRUE;
  8086.                 init_run_act(player,tx,ty,0);
  8087.             }
  8088.         }
  8089.         else
  8090. // send him to touch-line...
  8091.             init_run_act(player,tx,tly,0);
  8092.     }
  8093. }
  8094.  
  8095. /******************************************************************************
  8096. *****************************************************************************/
  8097.  
  8098. void intelligence(match_player *player)
  8099. {
  8100.     if ((player->control) && (!match_mode) && (ball_poss))
  8101.     {
  8102. // Player has just collected ball and been auto selected...
  8103.         user_controlled=player->control;
  8104.         user_intelligence(player);
  8105.     }
  8106.     else
  8107.     {
  8108.         char busy=0;
  8109.         int pnum=player->tm_player;
  8110.  
  8111.         if ((player->tm_leave) && (last_touch!=player->tm_player))
  8112.             player->tm_leave=FALSE;                                                // he can touch ball again!
  8113.  
  8114.         if (player->int_cnt)                //Is he busy?
  8115.         {
  8116.             if (--(player->int_cnt))
  8117.             {
  8118.                 if (((pnum==KP_A) || (pnum==KP_B)) && (player->int_move==I_INTERCEPT)
  8119.                     && (shot_pending>0))
  8120.                     busy=0;
  8121.                 else
  8122.                 {
  8123.                     busy=1;
  8124. /*
  8125.                     if (player->int_move==I_INTERCEPT && user_controlled && player->tm_strike>0)
  8126. // User player is interecpting ball but hasn't chosen special move...
  8127.                         go_to_path(player->tm_player);
  8128. */
  8129.                     if (player->int_move==I_OFF)
  8130.                     {
  8131. // He is going off!
  8132.                         if (player->tm_act==STAND_ACT)
  8133.                             init_off_int(player);
  8134.                     }
  8135.                     else
  8136.                     {
  8137.                         if (player->int_move==I_RUN_ON)
  8138. // Calling for pass ahead...
  8139.                         {
  8140.                             if (plr_facing(player->go_xoff,player->go_yoff,player))
  8141.                             {
  8142.                                 if (player->tm_comm<0)
  8143.                                     player->tm_comm=-player->tm_comm;
  8144.                             }
  8145.                             else
  8146.                             {
  8147.                                 if (player->tm_comm>0)
  8148.                                 {
  8149.                                     player->tm_comm=FALSE;
  8150.                                     player->tm_ccnt=0;
  8151.                                     reset_ideas(player);
  8152.                                 }
  8153.                             }
  8154.                         }
  8155.                         else
  8156.                         {
  8157.                             if (player->int_move==I_STEAL)
  8158.                             {
  8159.                                 if (player->tm_dist<STEAL_BODY_DIST)
  8160.                                 {
  8161.                                     reset_ideas(player);
  8162.                                     init_steal_act(player);
  8163.                                 }
  8164.                             }
  8165.                         }
  8166.                     }
  8167.                 }
  8168.             }
  8169.             else
  8170.             {
  8171.                 player->int_cnt=-1;
  8172.                 if (player->int_move==I_SAVE_WAIT) 
  8173.                 {
  8174.                     if (player->tm_act==RUN_ACT)
  8175.                         player->int_cnt=player->go_cnt+2;
  8176.                 
  8177.                     if (player->int_cnt>0)
  8178.                     {
  8179.                         player->int_move=I_INTERCEPT;
  8180.                         busy=1;
  8181.                     }
  8182.                     else
  8183.                         reset_ideas(player);
  8184.                 }
  8185.                 else
  8186.                     reset_ideas(player);
  8187.             }
  8188.         }
  8189.  
  8190.         if (player->tm_act<=TURN_ACT)    // Player is standing or running or turning!
  8191.         {
  8192.             if (!busy && !just_scored)
  8193.             {
  8194.                 if (player->guy_on<0)
  8195.                 {
  8196. // He has to be sent off!
  8197.                     init_off_int(player);
  8198.                 }
  8199.  
  8200.                 if (dead_ball_cnt==0)
  8201. // Are we in normal play...
  8202.                 {
  8203.                     if (!ball_poss)
  8204.                         free_ball(player);
  8205.                     else
  8206.                     {
  8207.                         if (ball_poss==pnum)
  8208.                             got_ball(player);
  8209.                         else
  8210.                         {
  8211.                             if ((pnum<12) && (ball_poss<12))
  8212. // My team A has ball!
  8213.                                 we_have_ball(player);
  8214.                             else
  8215.                             {
  8216.                                 if ((pnum>11) && (ball_poss>11))
  8217. // My team B has ball!
  8218.                                     we_have_ball(player);
  8219.                                 else
  8220.                                     opp_has_ball(player);
  8221.                             }
  8222.                         }
  8223.                     }
  8224.                 }
  8225.                 else
  8226.                 {
  8227. // Is ball holder looking for support...
  8228.                     if (ball_poss!=pnum && support_me)
  8229.                     {
  8230.                         if ((pnum<12) && (ball_poss<12))
  8231. // My team A has ball!
  8232.                             we_have_ball(player);
  8233.                         else
  8234.                             if ((pnum>11) && (ball_poss>11))
  8235. // My team B has ball!
  8236.                                 we_have_ball(player);
  8237.                     }
  8238.                 }
  8239.             }
  8240.         }
  8241.     }
  8242. }
  8243.  
  8244. /******************************************************************************
  8245. *****************************************************************************/
  8246. /*
  8247. void cant_block_opp(match_player *player,match_player *oplayer)
  8248. {
  8249.      int vx=(int)(ballx+(oplayer->go_txdis*8));     //look 8 turns ahead
  8250.      int vy=(int)(bally+(oplayer->go_tydis*8));
  8251.      vx-=player->tm_x;
  8252.      vy-=player->tm_y;
  8253.      if (calc_dist(vx,vy)<=tackle_range)
  8254.  
  8255. // In tackling range!
  8256.  
  8257.      {
  8258.          tackle_decide(player);
  8259.          if (flag)
  8260.             go_tackle(player,oplayer);
  8261.          else
  8262.              cant_tack_opp(player);
  8263.      }
  8264.      else
  8265.          cant_tack_opp(player);
  8266. }
  8267. */
  8268.  
  8269.